Changeset 1303
- Timestamp:
- 11/20/05 11:16:13 (2 years ago)
- Files:
-
- django/trunk/django/conf/global_settings.py (modified) (1 diff)
- django/trunk/django/middleware/sessions.py (modified) (2 diffs)
- django/trunk/docs/sessions.txt (modified) (3 diffs)
- django/trunk/docs/settings.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/conf/global_settings.py
r1250 r1303 196 196 SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks). 197 197 SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie. 198 SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request. 198 199 199 200 ######### django/trunk/django/middleware/sessions.py
r1035 r1303 1 from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN 1 from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN, SESSION_SAVE_EVERY_REQUEST 2 2 from django.models.core import sessions 3 3 from django.utils.cache import patch_vary_headers … … 68 68 except AttributeError: 69 69 modified = False 70 if modified :70 if modified or SESSION_SAVE_EVERY_REQUEST: 71 71 session_key = request.session.session_key or sessions.get_new_session_key() 72 72 new_session = sessions.save(session_key, request.session._session, django/trunk/docs/sessions.txt
r1211 r1303 42 42 43 43 * ``__delitem__(key)`` 44 Example: ``del request.session['fav_color']`` 44 Example: ``del request.session['fav_color']``. This raises ``KeyError`` 45 if the given ``key`` isn't already in the session. 45 46 46 47 * ``get(key, default=None)`` … … 159 160 {'user_id': 42} 160 161 161 Session cookies 162 =============== 163 164 A few `Django settings`_ give you control over the session cookie: 162 When sessions are saved 163 ======================= 164 165 By default, Django only saves to the session database when the session has been 166 modified -- that is if any of its dictionary values have been assigned or 167 deleted:: 168 169 # Session is modified. 170 request.session['foo'] = 'bar' 171 172 # Session is modified. 173 del request.session['foo'] 174 175 # Session is modified. 176 request.session['foo'] = {} 177 178 # Gotcha: Session is NOT modified, because this alters 179 # request.session['foo'] instead of request.session. 180 request.session['foo']['bar'] = 'baz' 181 182 To change this default behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting 183 to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save 184 the session to the database on every single request. 185 186 Note that the session cookie is only sent when a session has been created or 187 modified. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, the session cookie 188 will be sent on every request. 189 190 Similarly, the ``expires`` part of a session cookie is updated each time the 191 session cookie is sent. 192 193 Settings 194 ======== 195 196 A few `Django settings`_ give you control over session behavior: 165 197 166 198 SESSION_COOKIE_AGE … … 189 221 ``'hotclub'`` is a reference to the Hot Club of France, the band Django 190 222 Reinhardt played in. 223 224 SESSION_SAVE_EVERY_REQUEST 225 -------------------------- 226 227 Default: ``False`` 228 229 Whether to save the session data on every request. If this is ``False`` 230 (default), then the session data will only be saved if it has been modified -- 231 that is, if any of its dictionary values have been assigned or deleted. 191 232 192 233 .. _Django settings: http://www.djangoproject.com/documentation/settings/ django/trunk/docs/settings.txt
r1251 r1303 534 534 Reinhardt played in. 535 535 536 SESSION_SAVE_EVERY_REQUEST 537 -------------------------- 538 539 Default: ``False`` 540 541 Whether to save the session data on every request. See the `session docs`_. 542 536 543 SITE_ID 537 544 -------
