The session is stored in the Redis database and needs to be configured in the setting
Django-redis Chinese Documents
http://django-redis-chs.readthedocs.io/zh_CN/latest/#cache-backend
When using django1.6+, the default session is stored in the Database django_session table.
If you want to put the session in memory, you should configure it in the settings.py
Session_engine = "Django.contrib.sessions.backends.cache"
When used:
Added: request.session["userName" "Tom" query: name = request.session["userName"] Delete:del request.session[" userName"]
Well, the more complicated data is how to store it: like an object student.
According to other language habits, such as Java and C #, it should be that:
Stu = Student (name="Tom", age =new) added: request.session["user "] = Stu query: stu = request.session["user"] Delete:del request.session["user"]
When storing objects, it is not a problem if the session is stored in memory. But once stored in the database is not.
Why?
Because of what is stored in the database, it is necessary to be able to do JSON serialization .
Student cannot be serialized as JSON. Need to convert student into a dictionary, yes, a dictionary .
{"Name": "Tom", "Age": 12}
This can be stored in the database session.
Original address: 79116271
Django session stored to Redis database