On Mar 23, 8:30 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Mar 23, 2009 at 4:45 PM, Adam Yee <adamj...@gmail.com> wrote:
>
> > I'm using Django's builtin AuthenticationForm
>
> > Here's my login view:http://dpaste.com/18110/
>
> > Form submittal (not empty or empty fields) takes me back to the login
> > page with 'Did not login'. My debugging print statement isn't showing
> > up in the terminal, so is_valid is somehow returning false.
>
> > If I submit with empty fields, I don't get the default 'This field is
> > required' type of error messages that I would expect. I'm not sure
> > how clean() is working with the AuthenticationForm... Am I validating
> > correctly? Or is something happening in the authentication process?
> > Thanks.
>
> Your error() function is creating a brand-new blank AuthenticationForm that
> is passed in the context to the template, so the specific error message
> associated with whatever caused is_valid() to fail (which has been added to
> the original form's error_list) is being thrown away. If instead you pass
> back the form you called is_valid() on, then the template would be able to
> report the specific error that is causing the validation failure.
>
> Karen
Thanks Karen for that tip. The brand-new unbound form is removed.
So, I now pass the bound form, but still no validation error messages
show up. More importantly, is_valid is still returning false even
when I try logging in as a super user. I also removed checking for
is_active since the AuthenticationForm's clean should take care of
that and raise the correct validation error if the user isn't active.
Now with the error() func removed:
def stl_login(request):
if request.method == "POST":
form = AuthenticationForm(request.POST)
if form.is_valid(): # authenticate() should get called here from
form's clean()
print 'form is valid'
user = form.get_user()
print request.user
login(request, user)
return HttpResponseRedirect(reverse
('stlhome.views.stl_user_home'))
return render_to_response('stl_home.html', {
'script_name': request.META['SCRIPT_NAME'],
'form': form,
'error': 'Did not login' }
)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---