Python Django "ImportError: no module named hashcompat"

I am learning python + Django, reading the "start of django e-commerce", after installing django-db-log when running $ python manage.py runningerver there is a problem.

Unhandled exception in thread started by <function wrapper at 0x02C28DB0> Traceback (most recent call last): File "D:\Python27\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper fn(*args, **kwargs) File "D:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_run self.validate(display_num_errors=True) File "D:\Python27\lib\site-packages\django\core\management\base.py", line 308, in validate num_errors = get_validation_errors(s, app) File "D:\Python27\lib\site-packages\django\core\management\validation.py", line 34, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors self._populate() File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate self.load_app(app_name) File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app models = import_module('.models', app_name) File "D:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name) File "build\bdist.win32\egg\djangodblog\models.py", line 9, in <module> File "build\bdist.win32\egg\djangodblog\manager.py", line 23, in <module> File "build\bdist.win32\egg\djangodblog\helpers.py", line 5, in <module> ImportError: No module named hashcompat 
+4
source share
4 answers

You mean an outdated manual. The hashcompat module hashcompat been removed in Django 1.6, as you can read here .

Either install an older version of Django (1.5 or previous), or get a newer tutorial. You can also manually fix your code using Python's built-in functions, as indicated in the deletion notification, but for a beginner it can be a bit of a hassle :)

+6
source

I solved this using hashlib . I just added:

 try: from hashlib import sha1 as sha_constructor except ImportError: from django.utils.hashcompat import sha_constructor 
+4
source

hashcompat is already deprecated in django 1.6, it is better to use hashlib instead

0
source

If you still follow this, the version of django used in the book is 1.1 , and if you are using a higher version of django , try removing djangodblog from the list of applications in the setting.py file. It should work.

-1
source

Source: https://habr.com/ru/post/1479927/


All Articles