The example code for logging a user in here:
http://www.djangoproject.com/documentation/sessions/
is this:
def login(request):
u = users.get_object(username__exact=request.POST['username'])
if u.check_password(request.POST['password']):
request.session['user_id'] =
u.id
return HttpResponse("You're logged in.")
else:
return HttpResponse("Your username and password didn't match.")
It doesn't work for me. I googled and found some code here:
http://cvd.cidev.nl/wordpress/?p=245
That basically makes one small change resulting in this:
def login(request):
u = users.get_object(username__exact=request.POST['username'])
if u.check_password(request.POST['password']):
# CHANGE: different key used:
request.session[users.SESSION_KEY] =
u.id
return HttpResponse("You're logged in.")
else:
return HttpResponse("Your username and password didn't match.")
Which then works for me. Is this an error in the docs? Maybe I need to svn up?
Thanks,
Bryan