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/701d94cb-1e3d-4b3f-8497-7ec9df351a57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to