An *HTTP cookie* (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. The browser may store the cookie and send it back to the same server with later requests. Typically, an HTTP cookie is used to tell if two requests come from the same browser—keeping a user logged in, for example. It remembers stateful information for the stateless HTTP protocol.¶
The CSRF middleware and template tag provides easy-to-use protection against Cross Site Request Forgeries. This type of attack occurs when a malicious website contains a link, a form button or some JavaScript that is intended to perform some action on your website, using the credentials of a logged-in user who visits the malicious site in their browser.¶
Normally the csrftoken template tag will not work if CsrfViewMiddleware.processview or an equivalent like csrfprotect has not run. The view decorator ~requirescsrftoken~ can be used to ensure the template tag does work.¶
SESSION_ENGINE='django.contrib.sessions.backends.db'# 引擎(默认)# use 'django.contrib.sessions.backends.cached_db' for high trafficSESSION_COOKIE_NAME="sessionid"# Session的cookie保存在浏览器上时的key,即:sessionid=随机字符串(默认)SESSION_COOKIE_PATH="/"# Session的cookie保存的路径(默认)SESSION_COOKIE_DOMAIN=None# Session的cookie保存的域名(默认)SESSION_COOKIE_SECURE=False# 是否Https传输cookie(默认)SESSION_COOKIE_HTTPONLY=True# 是否Session的cookie只支持http传输(默认)SESSION_COOKIE_AGE=1209600# Session的cookie失效日期(2周)(默认)SESSION_EXPIRE_AT_BROWSER_CLOSE=False# 是否关闭浏览器使得Session过期(默认)SESSION_SAVE_EVERY_REQUEST=False# 是否每次请求都保存Session,默认修改之后才保存(默认)
The request object has a session attribute, and when the server executes the code, the session middleware and the session’s application operate together seamlessly. When you first store data in a session, Django saves the data server-side and associates it with a unique session ID. The server-side session data (object) is created when you store any data in the session and is saved either at the end of the request or when you explicitly call. The sessionid cookie is created client-side when you first store any data in the session.¶