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'
請問問題到底出在哪里呢??
添加回答
舉報
0/150
提交
取消