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、運(yùn)行??顯示?Hello?Admin?運(yùn)行正常
2、但是運(yùn)行???
顯示如下錯(cuò)誤:TypeErrorTypeError:?hello_user()?missing?1?required?positional?argument:?'name'
3、再次運(yùn)行http://127.0.0.1:5000/user/admin
顯示如下錯(cuò)誤:Not?FoundThe?requested?URL?was?not?found?on?the?server.?If?you?entered?the?URL?manually?please?check?your?spelling?and?try?again.
4、再次運(yùn)行
顯示如下錯(cuò)誤: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次運(yùn)行中是不是我的輸入是錯(cuò)誤導(dǎo)致的?那么參數(shù)應(yīng)該怎么傳呢?
5、因?yàn)橐陨洗a是教程中到源代碼,應(yīng)該是沒(méi)有錯(cuò)的。
后來(lái)我修改了源代碼中@app.route('/user/<name>')加入了<name>這個(gè)參數(shù)。
運(yùn)行??和??都顯示Hello?Admin?運(yùn)行正常。
但是運(yùn)行http://127.0.0.1:5000/user/kjkj
顯示如下錯(cuò)誤:TypeErrorTypeError:?redirect()?got?an?unexpected?keyword?argument?'guest'
請(qǐng)問(wèn)問(wèn)題到底出在哪里呢??
添加回答
舉報(bào)
0/150
提交
取消