为了账号安全,请及时绑定邮箱和手机立即绑定

flask中到url重定向报错,却参数,但不知道这个参数到底应该是怎么传送的

flask中到url重定向报错,却参数,但不知道这个参数到底应该是怎么传送的

胖猫CAT 2019-11-27 11:04:33
from flask import Flask, url_for from werkzeug.utils import redirect app = Flask(__name__) @app.route('/admin') def hello_admin():    return 'Hello Admin' @app.route('/guest/') def hello_guest(guest):    return 'Hello %s as Guest' % guest @app.route('/user/') def hello_user(name):    if name =='admin':       return redirect(url_for('hello_admin'))    else:       return redirect(url_for('hello_guest'), guest = name)      if __name__ == '__main__':    app.run(debug=True) 1、运行  显示 Hello Admin 运行正常 2、但是运行    显示如下错误:TypeErrorTypeError: hello_user() missing 1 required positional argument: 'name' 3、再次运行http://127.0.0.1:5000/user/admin 显示如下错误:Not FoundThe requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 4、再次运行 显示如下错误:Not FoundThe requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 第3、4次运行中是不是我的输入是错误导致的?那么参数应该怎么传呢? 5、因为以上代码是教程中到源代码,应该是没有错的。 后来我修改了源代码中@app.route('/user/<name>')加入了<name>这个参数。 运行  和  都显示Hello Admin 运行正常。 但是运行http://127.0.0.1:5000/user/kjkj 显示如下错误:TypeErrorTypeError: redirect() got an unexpected keyword argument 'guest' 请问问题到底出在哪里呢??
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1632 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信