[英]python manage.py runserver
I am trying to learn django.I try to start the server by running 我正在尝试学习django.I尝试通过运行来启动服务器
python manage.py runserver
but i get the following error 但我得到以下错误
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
please help me to remove this bug. 请帮助我删除此错误。
settings.py
settings.py
Iv'e played with django's config - changed AUTHENTICATION_BACKENDS
from 2 backends into a single one Iv'e使用django的配置玩-将
AUTHENTICATION_BACKENDS
从2个后端更改为一个
after a small debugging session iv'e discovered the solution 在进行小型调试会话后,iv'e找到了解决方案
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend')
or 要么
AUTHENTICATION_BACKENDS = 'django.contrib.auth.backends.ModelBackend'
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
Apparently your configuration is incorrect: 显然您的配置不正确:
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'
)
There should be commas in between those middleware module paths: 这些中间件模块路径之间应该有逗号:
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',
)
Without the commas, ('first' 'second' 'third')
in Python is the concatenated string value 'firstsecondthird'
. 没有逗号,Python中的(
'firstsecondthird'
('first' 'second' 'third')
是连接的字符串值'firstsecondthird'
。
When Django processes the MIDDLEWARE_CLASSES
setting, it iterates over its elements to load modules. 当Django处理
MIDDLEWARE_CLASSES
设置时,它将遍历其元素以加载模块。 If you separate the module paths by commas, then MIDDLEWARE_CLASSES
is a tuple, and Django correctly loads each module. 如果用逗号分隔模块路径,则
MIDDLEWARE_CLASSES
是一个元组,并且Django会正确加载每个模块。 If you omit all the commas, then MIDDLEWARE_CLASSES
is a string, so iterating over that value will be iterating over the letters of the string. 如果省略所有逗号,则
MIDDLEWARE_CLASSES
是一个字符串,因此迭代该值将迭代该字符串的字母。 The first letter is d
, so Django tries to load the path d
, which of course "doesn't look like a module path". 第一个字母是
d
,因此Django尝试加载路径d
,该路径当然“看起来不像模块路径”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.