У меня есть словарь с целочисленными ключами и классом Person в качестве значения.Мой метод GET по идентификатору пользователя работает, но мой метод GET UserList не работает.
Мой метод GET UserList возвращает:
{
"name": null,
"age": 0,
"address": null,
"city": null,
"state": null,
"zip_code": null
}
Фрагмент кода:
from flask import Flask, request, abort
from flask_restful import Api, Resource, fields, marshal_with
user_fields = {
'name': fields.String,
'age': fields.Integer,
'address': fields.String,
'city': fields.String,
'state': fields.String,
'zip_code': fields.String
}
class User(Resource):
@staticmethod
@marshal_with(user_fields)
def get(path_user_id):
# Checks to make sure the user exists otherwise throws an error
if path_user_id not in user_dict:
abort(400)
return user_dict.get(path_user_id)
# This one is not working
class UserList(Resource):
@staticmethod
@marshal_with(user_fields)
def get():
return user_dict.items()
class Person:
def __init__(self, name, age, address, city, state, zip_code):
self.name = name
self.age = age
self.address = address
self.city = city
self.state = state
self.zip_code = zip_code