Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Session not persistant in blueprint

Tags:

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
like image 317
user3525290 Avatar asked Apr 11 '17 12:04

user3525290


People also ask

How do I store session data Flask?

Sessions in Flask How are sessions implemented in Flask? In order to store data across multiple requests, Flask utilizes cryptographically-signed cookies (stored on the web browser) to store the data for a session. This cookie is sent with each request to the Flask app on the server-side where it's decoded.

Does Flask login use session?

Once the user has passed the password check, you will know that they have the correct credentials and you can log them in using Flask-Login. By calling login_user , Flask-Login will create a session for that user that will persist as the user stays logged in, which will allow the user to view protected pages.

Does Flask support client-side sessions?

Flask uses the client-side approach. Pros: Validating and creating sessions is fast (no data storage) Easy to scale (no need to replicate session data across web servers)

Can you store objects in Flask session?

Can you store objects in Flask session? While it may be an over-simplification, storing data in the session object in Flask can be considered client-side storage, since the data is stored in the web browser.


1 Answers

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

like image 78
Achim Munene Avatar answered Sep 28 '22 04:09

Achim Munene