Django1.6 运行manage.py 报错解决办法(ImportError)

django项目中运行manage.py

python manage.py runserver

出现如下错误提示:

Traceback (most recent call last):  
  File "manage.py", line 2, in <module>  
    from django.core.management import execute_manager  
ImportError: cannot import name execute_manager   

原因是django1.6中没有execute_manager

应将上述import execute_manager 修改为 import execute_from_command_line

附修改前后manage.py

#!/usr/bin/env python  
from django.core.management import execute_from_command_line  
import imp  
try:  
    imp.find_module('settings') # Assumed to be in the same directory.  
except ImportError:  
    import sys  
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)  
    sys.exit(1)  
  
import settings  
  
if __name__ == "__main__":  
   execute_from_command_line(settings)  

修改后:

import os  
import sys  
  
if __name__ == "__main__":  
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")  
  
    from django.core.management import execute_from_command_line  
  
    execute_from_command_line(sys.argv)  

其中settings的路径为项目中的实际路径,同样,如果urls 报ImportError错误,将settings.py相应的ROOT_URLCONF修改为ROOT_URLCONF = 'urls' 即可。

posted on 2018-05-14 00:18    阅读(1206)  评论(0编辑  收藏  举报