Following: http://www.djangobook.com/en/2.0/chapter14/
I used the request.session.set_test_cookie() method when I pass the
login form. I then use the request.session.test_cookie_worked() method
to see if the cookie was set.
My view is setup to tell me when the test_cookie_worked() method
fails, and it always shows that it fails. However, if I go into
Firefox and search for the cookie it is there.
What's going on?
** views.py **
def login_view(request, user=None):
if request.method == 'POST': # If the form has been submitted...
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
form = LoginForm(request.POST) # A form bound to the POST
data
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = authenticate(username=username,
password=password)
if user is not None:
if user.is_active:
login(request, user)
u =
User.objects.get(username__exact=request.POST['username'])
request.session['user'] = u.username
return HttpResponseRedirectView("logged in")
else:
return HttpResponse("Your account is
inactive.")
elif user is None:
return render_to_response('login.html',
{'error_message': 'You failed to
authenticate.'})
else:
return render_to_response('login.html', {'form': form,
'error_message': 'Invalid form. Did you leave one
of the fields blank?'})
else:
return HttpResponse("Cookies are required to login.")
else:
form = LoginForm() # An unbound form
request.session.set_test_cookie()
return render_to_response('login.html', {'form': form,
'error_message': 'Login please'})
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.