>From the docs for AuthenticationForm: "Takes request as its first 
positional argument, which is stored on the form instance for use by 
sub-classes."

https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.forms.AuthenticationForm

On Thursday, February 14, 2019 at 7:47:23 AM UTC-5, [email protected] 
wrote:
>
> Hi,
>
> I have just been following the Django documention on forms:
>
> https://docs.djangoproject.com/en/2.1/topics/forms/
>
> And I was having an issue with validating the posted data in the view 
> code. 
>
> I came across this Stack Overflow post :
>
>
> https://stackoverflow.com/questions/45824046/djangos-authentication-form-is-always-not-valid
>
> Where the solution to my problem was to use the data Keyword argument when 
> creating a form from the POST'd data. Looking back on the docs I noticed 
> that this wasn't specified. 
>
> So my view function now looks like this:
>
> def login(request):
>     if request.method == 'POST':
>         form = LoginForm(data=request.POST)  #<- This is where I had to use 
> the data kwarg
>         if form.is_valid():
>             return HttpResponseRedirect('#')
>         return render(request, 'scoreboard/login.html', {'form': form})
>     else:
>         return render(request, 'scoreboard/login.html', {'form': LoginForm()})
>
>
>
>
> [image: data kwarg.png]
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b02ec303-62b9-40ea-b048-f181aeb62a9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to