Friday, September 26, 2014

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

This is my login view:

def login_view(request,template_name='userauth/login.html'):

    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        print username
        print password
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                next_page = reverse('public:courselist')
            else:
                next_page = reverse('userauth:login')
                messages.error(request, "Ihr Account wurde deaktiviert. Bitte nehmen Sie Kontakt zu uns auf, wenn Sie Ihnen wieder aktivieren wollen.")
        else:
            next_page = reverse('userauth:login')
            messages.error(request, u'Ung\u00FCltiges Login')
    else:
        dictionary = {'form': form }
        return render_to_response('userauth/login.html', dictionary,  context_instance=RequestContext(request))

    return HttpResponseRedirect(next_page)


And this is my form:
from django import forms

class LoginForm(forms.Form):

    username = forms.CharField(
        max_length=100,
        widget=forms.TextInput,
        required=False,
        label="",
    )
    password = forms.CharField(
        max_length=100,
        widget=forms.TextInput,
        required=False,
        label="",
    )

I think I need to tell Django somehow about the form, but I do need really know where? Can someone please help me with figuring this out? When I print out the username and password they are both None. 

  Thanks in advance
        Sabine


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/db52e99e-0ce1-469c-91f7-80fdad3272eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment