Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when creating admin in django tutorial

Tags:

python

django

I am following the Django tutorial and am stuck on the second part, where I have to create an admin account.

I followed everything described in the tutorial up to that point and get the following error:

Traceback (most recent call last):
  File "e:\venvs\django_tutorial_venv\lib\site-packages\django\utils\module_loading.py", line 20, in import_string
    return getattr(module, class_name)
AttributeError: module 'django.contrib.auth.password_validation' has no attribute '        UserAttributeSimilarityValidator'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 26, in get_password_validators
    klass = import_string(validator['NAME'])
  File "e:\venvs\django_tutorial_venv\lib\site-packages\django\utils\module_loading.py", line 24, in import_string
    ) from err
ImportError: Module "django.contrib.auth.password_validation" does not define a "        UserAttributeSimilarityValidator" attribute/class

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   
    File "manage.py", line 15, in <module>
      execute_from_command_line(sys.argv)   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
      utility.execute()   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
      self.execute(*args, **cmd_options)   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 59, in execute
      return super().execute(*args, **options)   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\base.py", line 353, in execute
      output = self.handle(*args, **options)   
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 163, in handle
      validate_password(password2, self.UserModel(**fake_user_data))
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 44, in validate_password
      password_validators = get_default_password_validators()
    File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 19, in get_default_password_validators
      return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)           
    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.

One difference that I made was, that I put my virtualenvs in a folder, different than my project folder; could that be an issue? I correctly point to the venv folder in my project. What exactly is the error here?

like image 224
EInherjar Avatar asked Nov 25 '25 23:11

EInherjar


1 Answers

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',
    },
...
]
like image 153
DeshErBojhaa Avatar answered Nov 28 '25 14:11

DeshErBojhaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!