我之前已经完成了教程的第一部分,卡住了,意识到有几个版本的教程,删除了民意调查和mysite目录并重新开始。但是,当我跑
时$ python manage.py sql民意调查 结果是:
c:\Python27\Scripts\mysite>python manage.py sql polls
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280,
in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", lin
e 130, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 188, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 159, in _fetch
app = import_module(appname)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in im
port_module
__import__(name)
ImportError: No module named staticfilespolls
在settings.py中
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
'polls',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
我无法弄清楚错误的来源。
答案 0 :(得分:6)
您在django.contrib.staticfiles
设置中的INSTALLED_APPS
后缺少逗号:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', # HERE
'polls',
)
如果没有逗号,python会将django.contrib.staticfiles
和polls
字符串解释为单个字符串。
演示:
>>> s = ('what',
... 'a',
... 'wonderful'
... 'world')
>>> s
('what', 'a', 'wonderfulworld')
>>> s = ('what',
... 'a',
... 'wonderful',
... 'world')
>>> s
('what', 'a', 'wonderful', 'world')