Can't route to "/login" with flask?
21,900
Please read the flask quickstart Unique URLs / Redirection Behavior, URL canonicalization and Trailing slash in URLs - which style is preferred?
Comments
-
winoi over 3 years
When I type
/login
as url,it will go wrongFor example:
from flask import Flask ,url_for,render_template,request app = Flask(__name__) @app.route('/login') def index(): return "index" if __name__== "__main__": app.run()
The error turn out to be like this:
Not Found. The requested URL was not found on the server.
When I replace
/login
with/login/
or any other words like/log
, it will be all right. How does that happen? -
winoi about 11 yearsBut why it automatically replace "/login" with "/login/"? And then the browser will not find the page.
-
Joe about 11 yearsPlease read flask quickstart Unique URLs / Redirection Behavior part, it has explained the reason why flask do this way.
-
Joe about 11 yearsFor you given code, I can access
http://127.0.0.1:5000/login
,it will not redirect tohttp://127.0.0.1:5000/login/
; and when I try to acesshttp://127.0.0.1:5000/login/
, it report 404 error. It is in line with Unique URLs / Redirection Behavior. -
winoi about 11 yearsIt's all right now. "127.0.0.1:5000/login" was recorded in the browser.So when I type"127.0.0.1:5000/login" , it will add "/". It's the brower that troubles me. Thank you for your help.