mirror of https://github.com/django/django.git
Fixed #18348 -- Documented SesssionStore.create()
This commit is contained in:
parent
dde6288fbe
commit
32cf01c1c1
|
@ -487,14 +487,20 @@ An API is available to manipulate session data outside of a view::
|
||||||
>>> s = SessionStore()
|
>>> s = SessionStore()
|
||||||
>>> # stored as seconds since epoch since datetimes are not serializable in JSON.
|
>>> # stored as seconds since epoch since datetimes are not serializable in JSON.
|
||||||
>>> s['last_login'] = 1376587691
|
>>> s['last_login'] = 1376587691
|
||||||
>>> s.save()
|
>>> s.create()
|
||||||
>>> s.session_key
|
>>> s.session_key
|
||||||
'2b1189a188b44ad18c35e113ac6ceead'
|
'2b1189a188b44ad18c35e113ac6ceead'
|
||||||
|
|
||||||
>>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
|
>>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
|
||||||
>>> s['last_login']
|
>>> s['last_login']
|
||||||
1376587691
|
1376587691
|
||||||
|
|
||||||
|
``SessionStore.create()`` is designed to create a new session (i.e. one not
|
||||||
|
loaded from the session store and with ``session_key=None``). ``save()`` is
|
||||||
|
designed to save an existing session (i.e. one loaded from the session store).
|
||||||
|
Calling ``save()`` on a new session may also work but has a small chance of
|
||||||
|
generating a ``session_key`` that collides with an existing one. ``create()``
|
||||||
|
calls ``save()`` and loops until an unused ``session_key`` is generated.
|
||||||
|
|
||||||
If you're using the ``django.contrib.sessions.backends.db`` backend, each
|
If you're using the ``django.contrib.sessions.backends.db`` backend, each
|
||||||
session is just a normal Django model. The ``Session`` model is defined in
|
session is just a normal Django model. The ``Session`` model is defined in
|
||||||
``django/contrib/sessions/models.py``. Because it's a normal model, you can
|
``django/contrib/sessions/models.py``. Because it's a normal model, you can
|
||||||
|
|
Loading…
Reference in New Issue