Hi,

 

I encounter this problem that I failed to login to my app with correct
username and password. I'm wondering if there is something wrong with my
login form. Here is what it looks like:

 

from django import forms

from django.contrib import auth

 

class LoginForm(forms.Form):

    username = forms.CharField(label='User name:', max_length=30)

    password = forms.CharField(label='Password:',
widget=forms.PasswordInput, max_length=30)

    

    def clean(self):

        username = self.cleaned_data.get('username')

        password = self.cleaned_data.get('password')

        

        if username and password:

            self.user = auth.authenticate(username=username,
password=password)

            if self.user is None:

                raise forms.ValidationError("Your username or password is
incorrect.")

            elif not self.user.is_active:

                raise forms.ValidationError("Your account is inactive.")

        

        return self.cleaned_data

    

    def get_user(self):

        return self.user

 

And login template:

 

<html>

                <head>

                                <title>Murmur - Login</title>

                </head>

                <body>

            <form action="" method="post"> {% csrf_token %}

                                                <ul>

                                                                {{
form.as_ul }}

                                                </ul>

                                                <input type='submit'
value='Submit'>

                                </form>

                </body>

</html>

 

Every time I tried to login with correct username and password, it would go
back to login page with error message "Your username or password is
incorrect".

I guess there is something wrong with authenticate function. As it always
return None even with correct username and password.

 

Can somebody please help me with this issue?

 

thanks in advance.

 

Tom Lin

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to