Python Django“ImportError:没有名为hashcompat的模块”

2024-04-23 18:14:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在通过阅读《开始Django电子商务》来学习python+Django,在安装Django db log之后,在运行$python manage.py runserver时,出现了一个问题。

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

Tags: djangoinpyappdbgetmodelslib
3条回答

我用hashlib解决了这个问题。我刚刚补充道:

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

在django 1.6中,最好使用hashlib

你指的是一本过时的手册。在Django 1.6中删除了模块hashcompat,因为您可以读取here

要么安装较旧的Django版本(1.5或以前的版本),要么获取较新的教科书。您也可以按照删除通知中的建议使用Python内置代码手动修复代码,但对于初学者来说,这可能有点麻烦:)

相关问题 更多 >