I am trying to learn django.I try to start the server by running
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
Iv'e played with django's config - changed AUTHENTICATION_BACKENDS
from 2 backends into a single one
after a small debugging session iv'e discovered the solution
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'
.
When Django processes the MIDDLEWARE_CLASSES
setting, it iterates over its elements to load modules. If you separate the module paths by commas, then MIDDLEWARE_CLASSES
is a tuple, and Django correctly loads each module. 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. The first letter is d
, so Django tries to load the path d
, which of course "doesn't look like a module path".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.