码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-05-14 00:59:07      阅读:1156      评论:0      收藏:0      [点我收藏+]

标签:cto   python   sys.argv   serve   line   call   not   man   \n   

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‘ 即可。

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

标签:cto   python   sys.argv   serve   line   call   not   man   \n   

原文地址:https://www.cnblogs.com/areyouready/p/9034156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!