Ticket #13020: sessions.2.diff

File sessions.2.diff, 1.3 KB (added by elbarto, 5 years ago)
  • docs/topics/http/sessions.txt

     
    307307An API is available to manipulate session data outside of a view::
    308308
    309309    >>> from django.contrib.sessions.backends.db import SessionStore
     310    >>> import datetime
    310311    >>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
    311312    >>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10)
    312313    >>> s['last_login']
    313314    datetime.datetime(2005, 8, 20, 13, 35, 0)
    314315    >>> s.save()
    315316
     317If no ``session_key`` is provided, one will be generated automatically:
     318
     319    >>> from django.contrib.sessions.backends.db import SessionStore
     320    >>> import datetime
     321    >>> s = SessionStore()
     322    >>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10)
     323    >>> s['last_login']
     324    datetime.datetime(2005, 8, 20, 13, 35, 0)
     325    >>> s.save()
     326    >>> s.session_key
     327    '2b1189a188b44ad18c35e113ac6ceead'
     328
    316329If you're using the ``django.contrib.sessions.backends.db`` backend, each
    317330session is just a normal Django model. The ``Session`` model is defined in
    318331``django/contrib/sessions/models.py``. Because it's a normal model, you can
Back to Top