Python3 Flask路由变量显示为变量名称,而不是邮递员传递的值

问题描述 投票:2回答:1

我有以下python flask API路由:

@user_api.route("/<int:id>", methods=["GET"])
@Authentication.auth_required
def get_user(id):
    """
    Get a user
    """
    print(f"User id: {id}")
    user = user_schema.dump(UserModel.get_user(id))
    if not user:
        print(f"User id: {id} not found!")
        return custom_response({"error": f"User {id} not found!"}, 400)
    return custom_response(user_schema.dump(user), 200)

GET的邮递员的结尾总是以:

http://localhost:5555/api/v1/users/5

并且python控制台输出显示:

{
    "error": "User id not found!"
}

这意味着route变量最终以变量名而不是值的形式出现在函数中。 User id: id User id: id not found! int变量类型都会发生这种情况。真奇怪我想念什么?

python routes url-routing flask-restful url-parameters
1个回答
0
投票

这是由于将string传递给修饰函数时@Authentication.auth_required装饰函数的错误。它错过了一个星号。因此,它错误地传递了kwargs而不是**kwargs

© www.soinside.com 2019 - 2024. All rights reserved.