生成Flask令牌

2024-05-23 19:22:01 发布

您现在位置:Python中文网/ 问答频道 /正文

生成令牌时出现问题,当我点击“/api/token”时,不允许使用它的返回方法。谁能帮我。。。。提前谢谢

在--------------------应用程序副本--------------------在

@app.route('/api/token')
@basicAuth.login_required
def get_auth_token():
    token = g.user.generate_auth_token(600)
    return jsonify({ 'token': token.decode('ascii') })

在-----------模型.py--------------在

^{pr2}$

Tags: 方法tokenauthapiapp应用程序getdef
1条回答
网友
1楼 · 发布于 2024-05-23 19:22:01

在定义路由时,您需要设置想要使用的任何HTTP方法。例如,要接受GETPOST方法,可以执行以下操作:

@app.route('/api/token', methods=['GET', 'POST'])

烧瓶文件上说:

By default, a route only answers to GET requests, but that can be changed by providing the methods argument to the route() decorator.

发件人:http://flask.pocoo.org/docs/0.12/quickstart/#http-methods

相关问题 更多 >