python manage.py runserver

时间:2014-04-06 05:00:31

标签: python django python-2.7

我正在尝试学习django。我尝试通过运行

来启动服务器
python manage.py runserver

但是我收到以下错误

Django version 1.6.2, using settings 'coding.settings'
Starting development server at //127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 67, in __call__
    return self.application(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 187, i
n __call__
    self.load_middleware()
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 47, in
 load_middleware
   mw_class = import_by_path(middleware_path)
  File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 19,
in import_by_patherror_prefix, dotted_path))
ImproperlyConfigured: d doesn't look like a module path

请帮我删除此错误。

2 个答案:

答案 0 :(得分:3)

它位于settings.py

我玩过django的配置 - 将AUTHENTICATION_BACKENDS从2个后端改为单个

经过一个小小的调试会议后,我发现了解决方案

替换此表示形式:

AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend')

AUTHENTICATION_BACKENDS = 'django.contrib.auth.backends.ModelBackend'

与此一起:

AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']

答案 1 :(得分:1)

显然您的配置不正确:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.commonMiddleware'
    'django.contrib.sessions.middleware.SessionMiddleware'
    'django.middleware.csrf.CsrfViewMiddleware'
    'django.contrib.auth.middleware.AuthenticationMiddleware'
    'django.contrib.messages.middleware.MessageMiddleware'
)

这些中间件模块路径之间应该有逗号:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.commonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

如果没有逗号,Python中的('first' 'second' 'third')是连接的字符串值'firstsecondthird'

当Django处理MIDDLEWARE_CLASSES设置时,它会迭代其元素以加载模块。如果用逗号分隔模块路径,则MIDDLEWARE_CLASSES是一个元组,Django正确加载每个模块。如果省略所有逗号,则MIDDLEWARE_CLASSES是一个字符串,因此迭代该值将迭代字符串的字母。第一个字母是d,因此Django尝试加载路径d,当然“它看起来不像模块路径”。