Flask session lost data

前端 未结 1 1010
不知归路
不知归路 2020-12-22 07:35

I am testing a simple app to store data in session. I created the check to avoid resetting, but still getting data lost. Here is my code of app.py:

from fl         


        
相关标签:
1条回答
  • 2020-12-22 07:59

    Please consider the following:

    1. This is the most important point, for flask session to work, you need to configure a SECRET_KEY, like below:
    app.config["SECRET_KEY"] = 'YourSecretKey@123'
    
    1. I don't know, I just figured it out that you don't need the following line and it's corresponding import (it started working for me when I commented out this part, may be Flask-Session and Flask's inbuilt session are messing up with each other):
    Session(app)
    
    from flask_session import Session
    
    1. Don't directly update the session, if it's an array, do like below:
    note = request.form.get("note")
    temp = session['notes']
    temp.append(note)
    session['notes'] = temp
    

    I hope, it will work for you.

    0 讨论(0)
提交回复
热议问题