Okay, the problem was that the cookie was from my admin login (which I had not logged out of). When I deleted this cookie, the cookie test seemed to work. It does seem odd that I can't have two cookies for two different users on the same browser. Is there a way to change this? Maybe by incorporating the user id into the session id? My cookie was just called myproject_myapp_sessionid.
-Tim On Fri, Feb 26, 2010 at 2:07 AM, Timothy Kinney <timothyjkin...@gmail.com>wrote: > 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 django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.