# LoginView correct login details are incorrect

**URL:** <https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278>\
**Category:** Getting Started\
**Created:** [March 5, 2023, 12:33pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278 "2023-03-05T12:33:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Terramoto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/terramoto/32/12525_2.png) [@Terramoto](https://forum.djangoproject.com/u/Terramoto)\
**Post date:** [March 5, 2023, 12:33pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/1 "2023-03-05T12:33:17Z")

</div>

Hello,

I’m able to register new users in ‘My User’ db but when i try to login it fails with wrong details, authentication with superUser on Django db works.

MyUser in models.py:

```auto
class MyUser(AbstractBaseUser):
    # first name specs
    first_name = models.CharField(
        verbose_name='first_name', max_length=255, blank=False,
        error_messages={
            'blank': 'First name required!',
            'null': 'First name required!'
        }
    )
    # last name specs
    last_name = models.CharField(
        verbose_name='last_name', max_length=255, blank=False,
        error_messages={
            'blank': 'Last name required!',
            'null': 'Last name required!'
        }
    )

    # email specs
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True, validators=[validators.EmailValidator], error_messages={
            'unique': 'The email address may already exist on the system!',
            'blank': 'email address is required!',
            'invalid': 'Invalid email address!',
            'null': 'email address is required!'
        }
    )

    # username specs
    username = models.CharField(
        verbose_name='username', max_length=30, unique=True, blank=False, validators=[validators.RegexValidator('^[a-z0-9_-]{3,15}$')], error_messages={
            'unique': 'This username may exist on the system!',
            'blank': 'Username is required!',
            'invalid': 'Invalid username!',
            'null': 'Username required!'
        }
    )
    is_active = models.BooleanField(default=True)
    EMAIL_FIELD = 'email'
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['first_name', 'last_name', 'email']

```

urls.py:

```auto
path('login', LoginView.as_view(
        template_name='login.html'), name="login"),

```

settings.py:

```auto
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tags.apps.TagsConfig',
    'notes.apps.NotesConfig',
    'pages.apps.PagesConfig',
]

```

apps.py:

```auto
from django.apps import AppConfig

class PagesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    AUTH_USER_MODEL = 'pages.MyUser'
    name = 'pages'

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 5, 2023, 1:16pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/2 "2023-03-05T13:16:04Z")

</div>

> [@Terramoto](#):
>
> I’m able to register new users in ‘My User’ db

How are you registering new users? Are you doing it with your own view and form? Or are you registering them through the Django Admin?

If you’re using your own view and form, please post them here.

---

<div class="post-metadata">

**Author:** ![Terramoto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/terramoto/32/12525_2.png) [@Terramoto](https://forum.djangoproject.com/u/Terramoto)\
**Post date:** [March 5, 2023, 4:11pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/3 "2023-03-05T16:11:30Z")

</div>

I have my own register view with:

```auto
def user_register(request):
    form = models.CreateUserForm()
    if request.method == "POST":
        form = models.CreateUserForm(request.POST)
        user = models.MyUser.objects.filter(email=request.POST['email'])
        if form.is_valid():
            if user.exists():
                form.add_error('email', 'email already exists on the system!')
            else:
                form.save()
                messages.success(
                    request, 'Your account has been successfully registered! Please check your email account in order to verify your email!')
    context = {
        'form': form,
    }
    return render(request, 'register.html', context)

```

in models.py:

```auto
class CreateUserForm(UserCreationForm):

    class Meta(UserCreationForm.Meta):
        model = MyUser
        fields = ['first_name',
                  'last_name', 'username', 'email', 'password1', 'password2']

```

urls.py:

```auto
urlpatterns = [
    path('admin/', admin.site.urls),
    path('home', views.home_view, name="home"),
    path('', views.home_view, name="home"),
    path('register', views.user_register, name="register"),
    path('login', LoginView.as_view(
        template_name='login.html'), name="login"),
    path('send', views.send_view, name="send"),
    path('logout', views.user_logout, name="logout"),
    path('password_reset', views.password_reset, name="password_reset"),
]

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 5, 2023, 5:39pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/4 "2023-03-05T17:39:31Z")

</div>

The `AUTH_USER_MODEL` setting must be in your settings file, not in the app config. It’s a global (project-wide) setting, not limited to any individual part of the project.

See [Customizing authentication in Django | Django documentation | Django](https://docs.djangoproject.com/en/4.1/topics/auth/customizing/#substituting-a-custom-user-model)

---

<div class="post-metadata">

**Author:** ![Terramoto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/terramoto/32/12525_2.png) [@Terramoto](https://forum.djangoproject.com/u/Terramoto)\
**Post date:** [March 5, 2023, 6:13pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/5 "2023-03-05T18:13:32Z")

</div>

If i set it in settings, i get the following:  
“django.core.exceptions.ImproperlyConfigured: AUTH\_USER\_MODEL refers to model ‘pages.MyUser’ that has not been installed”

even after replacing pages.apps.PagesAppConfig with ‘pages’ in INSTALLED\_APPS.

I’ve tried clearing the migrations and cache but it comes up with this same error:

```auto
  File "D:\Django\python\mind\pages\models.py", line 4, in <module>
    from django.contrib.auth.forms import UserCreationForm
  File "D:\Django\python\mind\Lib\site-packages\django\contrib\auth\forms.py", line 18, in <module>
    UserModel = get_user_model()
                ^^^^^^^^^^^^^^^^
  File "D:\Django\python\mind\Lib\site-packages\django\contrib\auth\ __init__.py", line 176, in get_user_model
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'pages.MyUser' that has not been installed

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 5, 2023, 6:41pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/6 "2023-03-05T18:41:43Z")

</div>

What was the exact line for the `AUTH_USER_MODEL` that you had tried in your settings.py file?

Also:

> [@Terramoto](#):
>
> ```auto
> File "D:\Django\python\mind\pages\models.py", line 4, in <module>
> from django.contrib.auth.forms import UserCreationForm
> 
> ```

It looks like you’re trying to import UserCreationForm in your model. Why? I don’t see a reference to it in the portion of the models.py file you posted, and it’s generally not the right place to do this.

---

<div class="post-metadata">

**Author:** ![Terramoto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/terramoto/32/12525_2.png) [@Terramoto](https://forum.djangoproject.com/u/Terramoto)\
**Post date:** [March 5, 2023, 8:43pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/7 "2023-03-05T20:43:30Z")

</div>

It’s on my previous reply:

```auto
class CreateUserForm(UserCreationForm):

    class Meta(UserCreationForm.Meta):
        model = MyUser
        fields = ['first_name',
                  'last_name', 'username', 'email', 'password1', 'password2']

```

It’s then used in the registration view. I did it to customize the fields and user model. The part of the user registration seems to be working fine. Should i set this under views?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 5, 2023, 8:54pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/8 "2023-03-05T20:54:42Z")

</div>

Do you have the following line in your **models.py** file?:

> [@Terramoto](#):
>
> `from django.contrib.auth.forms import UserCreationForm`

If so, why?

Where are you referencing **that** class in your models.py? (And if you are, that is generally a mistake.)

---

<div class="post-metadata">

**Author:** ![Terramoto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/terramoto/32/12525_2.png) [@Terramoto](https://forum.djangoproject.com/u/Terramoto)\
**Post date:** [March 5, 2023, 11:28pm UTC](https://forum.djangoproject.com/t/loginview-correct-login-details-are-incorrect/19278/9 "2023-03-05T23:28:51Z")

</div>

thanks i missed this, i should’ve added this to views.
