Django 4.0.1 cannot import name 'SortedDict' from 'django.utils.datastructures'

881 Views Asked by At

My project isn't working! I need help!

I'm just fill in the forms. And click login button. Error:

Traceback (most recent call last):
  File "/home/pc/.local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/pc/.local/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/pc/Documents/Projects/Django/Travel/Web/views.py", line 92, in sign_in
    user = auth.authenticate(username=username, password=password)
  File "/home/pc/.local/lib/python3.10/site-packages/django/views/decorators/debug.py", line 42, in sensitive_variables_wrapper
    return func(*func_args, **func_kwargs)
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/__init__.py", line 77, in authenticate
    user = backend.authenticate(request, **credentials)
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/backends.py", line 48, in authenticate
    if user.check_password(password) and self.user_can_authenticate(user):
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 115, in check_password
    return check_password(raw_password, self.password, setter)
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/hashers.py", line 47, in check_password
    preferred = get_hasher(preferred)
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/hashers.py", line 129, in get_hasher
    return get_hashers()[0]
  File "/home/pc/.local/lib/python3.10/site-packages/django/contrib/auth/hashers.py", line 96, in get_hashers
    hasher_cls = import_string(hasher_path)
  File "/home/pc/.local/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/home/pc/.local/lib/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
    import_module(module_path)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/pc/.local/lib/python3.10/site-packages/django_scrypt/hashers.py", line 2, in <module>
    from django.utils.datastructures import SortedDict
ImportError: cannot import name 'SortedDict' from 'django.utils.datastructures' (/home/pc/.local/lib/python3.10/site-packages/django/utils/datastructures.py)

Anyone can help me? I tried many times. But nothing happened!

1

There are 1 best solutions below

0
On BEST ANSWER

SortedDict is deprecated as of Django 1.7 and removed in Django 1.9. Use ​collections.OrderedDict instead

from collections import OrderedDict