Changeset 7586 for django/trunk/docs/sessions.txt
- Timestamp:
- 06/07/08 15:28:06 (6 months ago)
- Files:
-
- django/trunk/docs/sessions.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/sessions.txt
r7329 r7586 81 81 82 82 * ``__getitem__(key)`` 83 83 84 Example: ``fav_color = request.session['fav_color']`` 84 85 85 86 * ``__setitem__(key, value)`` 87 86 88 Example: ``request.session['fav_color'] = 'blue'`` 87 89 88 90 * ``__delitem__(key)`` 91 89 92 Example: ``del request.session['fav_color']``. This raises ``KeyError`` 90 93 if the given ``key`` isn't already in the session. 91 94 92 95 * ``__contains__(key)`` 96 93 97 Example: ``'fav_color' in request.session`` 94 98 95 99 * ``get(key, default=None)`` 100 96 101 Example: ``fav_color = request.session.get('fav_color', 'red')`` 97 102 … … 102 107 * ``setdefault()`` (**New in Django development version**) 103 108 104 It also has these threemethods:109 It also has these methods: 105 110 106 111 * ``set_test_cookie()`` 112 107 113 Sets a test cookie to determine whether the user's browser supports 108 114 cookies. Due to the way cookies work, you won't be able to test this … … 111 117 112 118 * ``test_cookie_worked()`` 119 113 120 Returns either ``True`` or ``False``, depending on whether the user's 114 121 browser accepted the test cookie. Due to the way cookies work, you'll … … 117 124 118 125 * ``delete_test_cookie()`` 126 119 127 Deletes the test cookie. Use this to clean up after yourself. 128 129 * ``set_expiry(value)`` 130 131 **New in Django development version** 132 133 Sets the expiration time for the session. You can pass a number of 134 different values: 135 136 * If ``value`` is an integer, the session will expire after that 137 many seconds of inactivity. For example, calling 138 ``request.session.set_expiry(300)`` would make the session expire 139 in 5 minutes. 140 141 * If ``value`` is a ``datetime`` or ``timedelta`` object, the 142 session will expire at that specific time. 143 144 * If ``value`` is ``0`` then the user's session cookie will expire 145 when their browser is closed. 146 147 * If ``value`` is ``None``, the session reverts to using the global 148 session expiry policy. 149 150 * ``get_expiry_age()`` 151 152 **New in Django development version** 153 154 Returns the number of seconds until this session expires. For sessions 155 with no custom expiration (or those set to expire at browser close), this 156 will equal ``settings.SESSION_COOKIE_AGE``. 157 158 * ``get_expiry_date()`` 159 160 **New in Django development version** 161 162 Returns the date this session will expire. For sessions with no custom 163 expiration (or those set to expire at browser close), this will equal the 164 date ``settings.SESSION_COOKIE_AGE`` seconds from now. 165 166 * ``get_expire_at_browser_close()`` 167 168 **New in Django development version** 169 170 Returns either ``True`` or ``False``, depending on whether the user's 171 session cookie will expire when their browser is closed. 120 172 121 173 You can edit ``request.session`` at any point in your view. You can edit it … … 279 331 a browser. 280 332 333 **New in Django development version** 334 335 This setting is a global default and can be overwritten at a per-session level 336 by explicitly calling ``request.session.set_expiry()`` as described above in 337 `using sessions in views`_. 338 281 339 Clearing the session table 282 340 ==========================
