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

如题,django项目中运行manage.py

python manage.py runserver

出现如下错误提示

Traceback (most recent call last):
  File "manage.py", line 2, in 
    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相应的ROOT_URLCONF = 'urls' 修改。



你可能感兴趣的:(Django学习,Python学习)