Question

I am using django forms. Here is my code,

class LoginForm(forms.ModelForm):

    class Meta:
        model = User
        fields = ('username', 'password',)
        help_texts = {
            'username': ''
        }

I try to login the page using generated form. When I submit the button with empty values, It's gives "This field is required" validation default and I need this. But when I submit the button with correct username and correct password. It's gave the another validation like "User with this Username already exists." and I don't want this. How to stop particular validation rule in django. Advanced Thanks..

Was it helpful?

Solution

You shouldn't be using a ModelForm for this: they are for creating new instances or editing existing ones. Another problem is that passwords are stored in hashed form in the database, so the password entered in the form would not match the version in the db.

There is an AuthenticationForm in django.contrib.auth that you should use which takes care of all this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top