On 5 Jan, 10:47, Deniz Dogan <[email protected]> wrote:
> Hi
>
> I'm having trouble when using the AuthenticationForm in Django. It
> tells me that I haven't enabled cookies, even though I'm completely
> sure that I have. I get this error:
>
> "Your Web browser doesn't appear to have cookies enabled. Cookies are
> required for logging in."
>
> I've tried restarting Django, the browser, tried several different
> browsers, etc. I'm completely lost. I read somewhere that the login
> view has to be called with a GET request before it's called with a
> POST for this to work, but it *is* called with a GET to actually view
> the login form in the first place.
>
> Below is the login view that I'm using.
>
> ---------------------------------
>
> def user_login(request):
>
>     if request.user.is_authenticated():
>         return HttpResponseRedirect('/main/')
>
>     if request.method == 'POST':
>         form = AuthenticationForm(request.POST)
>         if form.is_valid():
>             login(request, form.get_user())
>             return HttpResponseRedirect('/main/')
>         else:
>             return render_to_response('login.html', { 'form' : form })
>
>     else:
>         form = AuthenticationForm()
>         return render_to_response('login.html', { 'form' : form })
>
> ---------------------------------
>
> Thanks,
> Deniz

I finally managed to help the problem by doing AuthenticationForm
(None, request.POST). I have understood that None should represent the
HTTPRequest object so that the form can validate that cookies have
been enabled. Passing None bypasses this check, but is there any real
danger in doing this?

Thanks again,
Deniz
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to