Changeset 2788
- Timestamp:
- 04/28/06 21:57:58 (2 years ago)
- Files:
-
- django/branches/magic-removal/docs/sessions.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/docs/sessions.txt
r2744 r2788 11 11 ================= 12 12 13 Session functionality is enabled by default. 14 15 You can turn session functionality on and off by editing the 16 ``MIDDLEWARE_CLASSES`` setting. To activate sessions, make sure 17 ``MIDDLEWARE_CLASSES`` contains ``"django.contrib.sessions.middleware.SessionMiddleware"``. 13 Sessions are implemented via middleware_. 14 15 Turn session functionality on and off by editing the ``MIDDLEWARE_CLASSES`` 16 setting. To activate sessions, make sure ``MIDDLEWARE_CLASSES`` contains 17 ``"django.contrib.sessions.middleware.SessionMiddleware"``. 18 19 The default ``settings.py`` created by ``django-admin.py startproject`` has 20 ``SessionMiddleware`` activated. 18 21 19 22 If you don't want to use sessions, you might as well remove the … … 21 24 bit of overhead. 22 25 26 .. _middleware: http://www.djangoproject.com/documentation/middleware/ 27 23 28 Using sessions in views 24 29 ======================= 25 30 26 Each ``HttpRequest`` object -- the first argument to any Django view function -- 27 has a ``session`` attribute, which is a dictionary-like object. You can read 28 it and write to it.31 When ``SessionMiddleware`` is activated, each ``HttpRequest`` object -- the 32 first argument to any Django view function -- will have a ``session`` 33 attribute, which is a dictionary-like object. You can read it and write to it. 29 34 30 35 It implements the following standard dictionary methods: 31 32 * ``__contains__(key)``33 Example: ``'fav_color' in request.session``34 36 35 37 * ``__getitem__(key)`` … … 42 44 Example: ``del request.session['fav_color']``. This raises ``KeyError`` 43 45 if the given ``key`` isn't already in the session. 46 47 * ``__contains__(key)`` 48 Example: ``'fav_color' in request.session`` 44 49 45 50 * ``get(key, default=None)``
