So I should be using: form = AuthenticatioForm(request)
It seems odd that the signature for various form aren't the same, at least in respect to *args. **kwags I can understand being different. Regardless I wanted to highlight a gotcha that wasn't immediately obvious. Also, I received no error from using: form = AuthenticatioForm(request.POST) If it's wrong shouldn't django let me know? On Friday, February 15, 2019 at 1:49:55 AM UTC+11, Tim Graham wrote: > > 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, > james.pete...@gmail.com 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/8bc872d2-8e23-4b8f-b4cc-d21479898e87%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.