Edited docs/sessions.txt changes from [6333]
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6344 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c079d52fe7
commit
b448593432
|
@ -18,13 +18,13 @@ To enable session functionality, do the following:
|
||||||
``MIDDLEWARE_CLASSES`` contains ``'django.contrib.sessions.middleware.SessionMiddleware'``.
|
``MIDDLEWARE_CLASSES`` contains ``'django.contrib.sessions.middleware.SessionMiddleware'``.
|
||||||
The default ``settings.py`` created by ``django-admin.py startproject`` has
|
The default ``settings.py`` created by ``django-admin.py startproject`` has
|
||||||
``SessionMiddleware`` activated.
|
``SessionMiddleware`` activated.
|
||||||
|
|
||||||
* Add ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting,
|
* Add ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting,
|
||||||
and run ``manage.py syncdb`` to install the single database table
|
and run ``manage.py syncdb`` to install the single database table
|
||||||
that stores session data.
|
that stores session data.
|
||||||
|
|
||||||
**New in development version**: this step is optional if you're not using
|
**New in development version**: this step is optional if you're not using
|
||||||
the database session backend; see `configuring the session engine`_.
|
the database session backend; see `configuring the session engine`_.
|
||||||
|
|
||||||
If you don't want to use sessions, you might as well remove the
|
If you don't want to use sessions, you might as well remove the
|
||||||
``SessionMiddleware`` line from ``MIDDLEWARE_CLASSES`` and ``'django.contrib.sessions'``
|
``SessionMiddleware`` line from ``MIDDLEWARE_CLASSES`` and ``'django.contrib.sessions'``
|
||||||
|
@ -50,7 +50,7 @@ To use file-based sessions, set the ``SESSION_ENGINE`` setting to
|
||||||
|
|
||||||
You might also want to set the ``SESSION_FILE_PATH`` setting (which
|
You might also want to set the ``SESSION_FILE_PATH`` setting (which
|
||||||
defaults to ``/tmp``) to control where Django stores session files. Be
|
defaults to ``/tmp``) to control where Django stores session files. Be
|
||||||
sure to check that your web server has permissions to read and write to
|
sure to check that your Web server has permissions to read and write to
|
||||||
this location.
|
this location.
|
||||||
|
|
||||||
Using cache-based sessions
|
Using cache-based sessions
|
||||||
|
@ -64,8 +64,8 @@ you've configured your cache; see the `cache documentation`_ for details.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
You probably don't want to use cache-based sessions if you're not using
|
You should probably only use cache-based sessions if you're using the
|
||||||
the memcached cache backend. The local memory and simple cache backends
|
memcached cache backend. The local memory and simple cache backends
|
||||||
don't retain data long enough to be good choices, and it'll be faster
|
don't retain data long enough to be good choices, and it'll be faster
|
||||||
to use file or database sessions directly instead of sending everything
|
to use file or database sessions directly instead of sending everything
|
||||||
through the file or database cache backends.
|
through the file or database cache backends.
|
||||||
|
@ -194,8 +194,9 @@ Here's a typical usage example::
|
||||||
Using sessions out of views
|
Using sessions out of views
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
The ``SessionStore`` which implements the session storage method can be imported
|
**New in Django development version**
|
||||||
and a API is available to manipulate the session data outside of a view::
|
|
||||||
|
An API is available to manipulate session data outside of a view::
|
||||||
|
|
||||||
>>> from django.contrib.sessions.engines.db import SessionStore
|
>>> from django.contrib.sessions.engines.db import SessionStore
|
||||||
>>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
|
>>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
|
||||||
|
@ -204,15 +205,15 @@ and a API is available to manipulate the session data outside of a view::
|
||||||
datetime.datetime(2005, 8, 20, 13, 35, 0)
|
datetime.datetime(2005, 8, 20, 13, 35, 0)
|
||||||
>>> s.save()
|
>>> s.save()
|
||||||
|
|
||||||
Or if you are using the ``django.contrib.sessions.engine.db`` each
|
If you're using the ``django.contrib.sessions.engine.db`` backend, each
|
||||||
session is just a normal Django model. The ``Session`` model
|
session is just a normal Django model. The ``Session`` model is defined in
|
||||||
is defined in ``django/contrib/sessions/models.py``. Because it's a normal
|
``django/contrib/sessions/models.py``. Because it's a normal model, you can
|
||||||
model, you can access sessions using the normal Django database API::
|
access sessions using the normal Django database API::
|
||||||
|
|
||||||
>>> from django.contrib.sessions.models import Session
|
>>> from django.contrib.sessions.models import Session
|
||||||
>>> s = Session.objects.get(pk='2b1189a188b44ad18c35e113ac6ceead')
|
>>> s = Session.objects.get(pk='2b1189a188b44ad18c35e113ac6ceead')
|
||||||
>>> s.expire_date
|
>>> s.expire_date
|
||||||
datetime.datetime(2005, 8, 20, 13, 35, 12)
|
datetime.datetime(2005, 8, 20, 13, 35, 12)
|
||||||
|
|
||||||
Note that you'll need to call ``get_decoded()`` to get the session dictionary.
|
Note that you'll need to call ``get_decoded()`` to get the session dictionary.
|
||||||
This is necessary because the dictionary is stored in an encoded format::
|
This is necessary because the dictionary is stored in an encoded format::
|
||||||
|
@ -306,10 +307,10 @@ Default: ``django.contrib.sessions.backends.db``
|
||||||
|
|
||||||
Controls where Django stores session data. Valid values are:
|
Controls where Django stores session data. Valid values are:
|
||||||
|
|
||||||
* ``'django.contrib.sessions.backends.db'``
|
* ``'django.contrib.sessions.backends.db'``
|
||||||
* ``'django.contrib.sessions.backends.file'``
|
* ``'django.contrib.sessions.backends.file'``
|
||||||
* ``'django.contrib.sessions.backends.cache'``
|
* ``'django.contrib.sessions.backends.cache'``
|
||||||
|
|
||||||
See `configuring the session engine`_ for more details.
|
See `configuring the session engine`_ for more details.
|
||||||
|
|
||||||
SESSION_FILE_PATH
|
SESSION_FILE_PATH
|
||||||
|
|
Loading…
Reference in New Issue