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?

Share:
21,900
winoi
Author by

winoi

Shanghai University. Master on EE.

Updated on December 29, 2020

Comments

  • winoi
    winoi over 3 years

    When I type /login as url,it will go wrong

    For 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
    winoi about 11 years
    But why it automatically replace "/login" with "/login/"? And then the browser will not find the page.
  • Joe
    Joe about 11 years
    Please read flask quickstart Unique URLs / Redirection Behavior part, it has explained the reason why flask do this way.
  • Joe
    Joe about 11 years
    For you given code, I can access http://127.0.0.1:5000/login,it will not redirect to http://127.0.0.1:5000/login/; and when I try to acess http://127.0.0.1:5000/login/, it report 404 error. It is in line with Unique URLs / Redirection Behavior.
  • winoi
    winoi about 11 years
    It'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.