亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 1758 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號