[Django]-Error when creating admin in django tutorial

4👍

Okay, after some digging around, I found out that the solution was fairly simple. The line

File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 29, in get_password_validators
      raise ImproperlyConfigured(msg % validator['NAME']) 
django.core.exceptions.ImproperlyConfigured: The module in NAME could not be imported: django.contrib.auth.password_validation.        UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting.

is faulty, specifically, I conformed to the pep8 standard and I mistakenly added spaces in front of UserAttributeSimilarityValidator, so it read the full string with spaces included, that’s why it couldn’t find the package. I corrected the strings, ignoring pep8 and it worked.

9👍

To add more detailed answer on @Elnherjar ‘s answer,
on your settings.py don’t do

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.\
            UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.\
            MinimumLengthValidator',
    },
   ...
]

which appends a tab in those strings. A cleaner approach can be,

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.' +
        'UserAttributeSimilarityValidator',
    },
...
]

2👍

Following line of code in settings resolved the issue.

AUTH_PWD_MODULE="django.contrib.auth.password_validation."

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": f"{AUTH_PWD_MODULE}UserAttributeSimilarityValidator",
    },
    {
        "NAME": f"{AUTH_PWD_MODULE}MinimumLengthValidator",
    },
    {
        "NAME": f"{AUTH_PWD_MODULE}CommonPasswordValidator",
    },
    {
        "NAME": f"{AUTH_PWD_MODULE}NumericPasswordValidator",
    },
]

I found it more readable. The actual issue is when try format string using \, the name is changed.

1👍

following your traceback you might need to Look at your settings and look for AUTH_PASSWORD_VALIDATORS, there may be some syntax error

👤slqq

Leave a comment