#13020 closed (fixed)
Django session documentation is wrong
Reported by: | bryan | Owned by: | elbarto |
---|---|---|---|
Component: | Documentation | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
http://docs.djangoproject.com/en/1.1/topics/http/sessions/#using-sessions-out-of-views
You shouldn't pass a session_key into SessionStore, that gets generated automatically when you save() it.
>>> from django.contrib.sessions.backends.db import SessionStore >>> s = SessionStore() >>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10) >>> s['last_login'] datetime.datetime(2005, 8, 20, 13, 35, 0) >>> s.save() >>> s.session_key '2b1189a188b44ad18c35e113ac6ceead
>>> from django.contrib.sessions.models import Session >>> s = Session.objects.get(pk='2b1189a188b44ad18c35e113ac6ceead') >>> s.expire_date datetime.datetime(2005, 8, 20, 13, 35, 12)
Attachments (2)
Change History (9)
comment:1 by , 15 years ago
Component: | Uncategorized → Documentation |
---|
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Owner: | changed from | to
---|
by , 14 years ago
Attachment: | sessions.diff added |
---|
comment:4 by , 14 years ago
Has patch: | set |
---|
comment:5 by , 14 years ago
I have notice that it still missing an import (datetime) in current source and also in my patch.
When:
slast_login = datetime.datetime(2005, 8, 20, 13, 35, 10)
It returns:
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'datetime' is not defined
I fixed it in new patch.
by , 14 years ago
Attachment: | sessions.2.diff added |
---|
comment:6 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:7 by , 14 years ago
Note:
See TracTickets
for help on using tickets.
You *should* provide a key if you know which session you want to use. If provide a session key, Django will use that key specifically. If you omit the key, one will be generated. However, as far as I can tell, the fact that a session key will be generated if one isn't provided isn't a documented behaviour.