2013-05-09 165 views
4

我在安裝django-db-log,運行$ python manage.py runserver之後,閱讀「開始django電子商務」,學習了python + Django,是一個問題。Python Django「ImportError:No module named hashcompat」

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 
+1

聽起來像你已經安裝在前一個之上的新Django。嘗試卸載/安裝Django。 – alecxe 2013-05-09 14:13:45

回答

6

你指的是過時的手冊。在Django 1.6中刪除了模塊hashcompat,因爲您可以閱讀here

要麼安裝舊的Django版本(1.5或以前版本),要麼獲得更新的教科書。您也可以通過手動使用Python內建在除名通知告知解決您的代碼,但是對於初學者可以不大不小的麻煩:)

+0

非常感謝!我嘗試你的解決方案,問題解決了。再次感謝。 – xufeng 2013-05-10 02:17:46

4

的我用hashlib解決了它。我只是說:

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

如果依然遵循的是,在本書中使用的django版本是1.1,如果你正在使用的django更高的版本,然後嘗試從應用程序列表中setting.py文件中刪除djangodblog 。它應該工作。