I am using a blueprint to build a web application. I am having issue with sessions not being persistent. I can start the session but when I click a link the session is lost. What am I doing incorrectly? I am not using a database to login I am just hard coding. When I submit I do
session['username'] = me. On the page that I redirect to after the login it works. But when I click a link from that page, the session is lost. The
session['username'] is gone. I do have my secret key set as well. It is hard coded in my config file. In my admin folder I have a routes file with my login. The login works, but when I click a link to go to a different page the username is lost.
C:.
└───blueprintsite
├───admin
│ ├───templates
│ │ └───admin
│ └───__pycache__
├───reports
│ └───__pycache__
├───users
│ ├───templates
│ │ └───site
│ └───__pycache__
├───static
│ ├───css
│ ├───fonts
│ ├───images
│ │ ├───media
│ │ ├───people
│ │ └───preview
Hello you can start using Flask-Login to handle your user authentication and session management, good things is with flask-login you wont have to worry about session management across your blueprints as it will automatically do that for you. I have been using it for my Blueprint applications for years now and it works perfectly for me.
Give it a read and I hope it helps you
This issue may occur when the SESSION_COOKIE_PATH
(or APPLICATION_ROOT
) configuration values for your Flask app do not include the path that the Blueprint is set up to route for.
For example, if the APPLICATION_ROOT
of your app is set up to be /pages
, but your Blueprint is prefixed for /admin
, the session cookie of the former won't be valid for the latter. Setting SESSION_COOKIE_PATH
explicitly to /
should do the trick, in this case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.