django - Technical Session
Others
2019-11-16 15:21:57
views: null
django- Technical Session
1、Cookie
- Stored in the browser
- It is a key to the structure
- And the key is a string value
- You can set the survival time
2、Session
- Stored on the server
- It is a key to the structure
- Key is a string, to an object
- You can set the survival time
3, Session and Cookie relationship
- When the server for the first time session, the server creates a session object
- ID server session will object, wrote in the browser's Cookie
- Cookie key is sessionid, value ID session object
- When the server uses the session, the server looks for a called sessionid the Cookie from the Cookie in the corresponding browser
- If the corresponding sessionid find, obtain the corresponding value, and to find the corresponding session in the server
- If you can not find the corresponding sessionid, the server will create a new session object
Enable session in the django
1, python manage.py migrate migration built-in application, generate relevant table
2, generates a table django_session
- session_key session key corresponding to
- session_data session content corresponding
- expire_date session expiration time
In the program through request.session
to get the session object
session for storage and user / browser -related data
session result is stored in the form of a dictionary
Corresponding to a session must be stored serialized object JSON
session default expiration time is 2 weeks
django global configuration file is global_settings.py
CTRL + N global_settings
session Destruction (exit)
- flush()
- Forcibly cleared, the demise of the current session
- clear_expired()
- The session has expired Clear All
Origin www.cnblogs.com/leomessi10/p/11871716.html