How to use cookie based session like Flask?
See original GitHub issueI saw in the docs there is a mention of session but I couldn’t find any code example.
Specifically didn’t see how to leverage the app’s secret key and decrypt the message on subsequent requests.
I would like to do the following Flask route in starlette :
Also, is there a way to flash messages like Flask? Trying to migrate a project
@app.route("/login", methods=["GET", "POST"])
def login():
email = None
if request.method == "POST":
#Check authentication in db here...
session["email"] = request.form.get("email")
return redirect(url_for("user_home"))
elif "email" in session:
return redirect(url_for("user_home"))
return render_template("public.html", email=email)
@app.route("/home")
def user_home():
#Not logged in
if 'email' not in session :
return redirect(url_for('login'))
return render_template('home.html')
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Sessions in Flask - OverIQ.com
Session is yet another way to store user-specific data between requests. It works similar to cookies. To use session you must set the...
Read more >Python Flask: keeping track of user sessions? How to get ...
You can access request cookies through the request.cookies dictionary and set cookies by using either make_response or just storing the ...
Read more >Authentication with Cookies and Sessions in Flask
In Chrome, you can try this out in the application tab. Go to the "Cookies" section under "Storage", and then tamper with the...
Read more >Get and set cookies with Flask - Python Tutorial
In Flask, set the cookie on the response object.Use the make_response() function to get the response object from the return value of the...
Read more >Flask-Session — Flask-Sessions 0.0.4 documentation
Configuration¶ ; SESSION_PERMANENT, Whether use permanent session or not, default to be True ; SESSION_USE_SIGNER, Whether sign the session cookie sid or not,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
First of all you need register SessionMiddleware, after that you can use request.session https://www.starlette.io/middleware/#sessionmiddleware
1. Redirecting (url_for) in my example.
2. Flashing message on page.
Starlette doesn’t have a flash functionality.