端点抛出错误如何不可调用?

时间:2018-02-17 18:17:36

标签: flask

我已在下面实施了基本的view.py     来自flask_restplus导入资源,reqparse

# the below order matters
from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)

parser = reqparse.RequestParser()
parser.add_argument('email', help = 'This field cannot be blank', required = True)
parser.add_argument('password', help = 'This field cannot be blank', required = True)

@auth.route('/registration')
class UserRegistration(Resource):
    def post(self):
        data = parser.parse_args()
        new_user = models.Users(
            email = data['email'],
            password = data['password']
        )
        try:
            new_user.save_to_db()
            return {
                'message': 'User with email: {} was created.'.format( data['email'])
            }
        except:
            return {'message': 'Something went wrong'}, 500

但是当我使用POST方法访问注册端点时,我收到以下错误:

TypeError: 'UserRegistration' object is not callable

1 个答案:

答案 0 :(得分:0)

你的课程不可调用......你的装饰师正在调用它。

尝试在您的班级中添加构造函数(__init__)。或者,如果装饰器需要一个函数,则将其转换为函数。