Ticket #13020: sessions.2.diff
File sessions.2.diff, 1.3 KB (added by , 14 years ago) |
---|
-
docs/topics/http/sessions.txt
307 307 An API is available to manipulate session data outside of a view:: 308 308 309 309 >>> from django.contrib.sessions.backends.db import SessionStore 310 >>> import datetime 310 311 >>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead') 311 312 >>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10) 312 313 >>> s['last_login'] 313 314 datetime.datetime(2005, 8, 20, 13, 35, 0) 314 315 >>> s.save() 315 316 317 If 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 316 329 If you're using the ``django.contrib.sessions.backends.db`` backend, each 317 330 session is just a normal Django model. The ``Session`` model is defined in 318 331 ``django/contrib/sessions/models.py``. Because it's a normal model, you can