Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't route to "/login" with flask?

Tags:

python

url

flask

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?

like image 299
winoi Avatar asked Feb 19 '13 11:02

winoi


People also ask

How does flask login work?

So let’s dive into the coding part. Flask-login uses Cookie-based Authentication. When the client logins via his credentials, Flask creates a session containing the user ID and then sends the session ID to the user via a cookie, using which he can log in and out as and when required.

How do I restrict user access to a flask page?

You can use the Flask-Login module to do access control. It provides user session management for Flask: logging in, logging out, and remembering session. The module stores the user ID, restricts views to logged in users, protects cookies and has many other features. The Flask-login module we use is.

How to use flask-login?

Flask-login uses Cookie-based Authentication. When the client logins via his credentials, Flask creates a session containing the user ID and then sends the session ID to the user via a cookie, using which he can log in and out as and when required. Now that it’s installed, let’s move into the coding part! 1. Coding the models.py file

How to login using cookie-based authentication in flask-login?

Flask-login uses Cookie-based Authentication. When the client logins via his credentials, Flask creates a session containing the user ID and then sends the session ID to the user via a cookie, using which he can log in and out as and when required. First we need to install the Flask-Login


1 Answers

Please read the flask quickstart Unique URLs / Redirection Behavior, URL canonicalization and Trailing slash in URLs - which style is preferred?

like image 65
Joe Avatar answered Sep 29 '22 10:09

Joe