Monday, September 29, 2014

Re: at django login my request.POST.get data are all empty, I struggle with what I missed there

Use a login view like this:
def login_view(request):
= LoginForm(initial={'email':})
if request.POST.get('login'):
= LoginForm(data=request.POST)
if form.is_valid():
if user.is_active:
.login(request, form.user)
return redirect('public:courselist')
.error(request, "Ihr Account wurde deaktiviert. Bitte nehmen Sie Kontakt zu uns auf, wenn Sie Ihnen wieder aktivieren wollen.")
return redirect('userauth:login')
return render(request, 'userauth/login.html', {'form': form})

and add a clean() method to your form like this:
    def clean(self):
if self.cleaned_data.get('username') and self.cleaned_data.get('password'):
self.user = authenticate(username=self.cleaned_data['username'], password=self.cleaned_data['password'])
if self.user is None:
raise forms.ValidationError('Please enter a correct username and password.')
elif not self.user.is_active:  # or leave this out and handle inactive case in your view above.
raise forms.ValidationError('This account is inactive.')
return self.cleaned_data

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment