gpt4 book ai didi

python - django tutorial no module named staticfilespolls 错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:45 24 4
gpt4 key购买 nike

我之前完成了教程的第一部分,卡住了,意识到教程有多个版本,删除了 polls 和 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'),
}
}

我不知道错误是从哪里来的。

最佳答案

INSTALLED_APPS 设置中的 django.contrib.staticfiles 后面缺少逗号:

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.staticfilespolls 字符串解释为单个字符串。

演示:

>>> s = ('what', 
... 'a',
... 'wonderful'
... 'world')
>>> s
('what', 'a', 'wonderfulworld')

>>> s = ('what',
... 'a',
... 'wonderful',
... 'world')
>>> s
('what', 'a', 'wonderful', 'world')

关于python - django tutorial no module named staticfilespolls 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22902219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com