python - django tutorial no module named staticfilespolls 错误

标签 python django sqlite django-settings django-staticfiles

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

相关文章:

sqlite - 单个 SQLite 数据库的多个文件

ios - iPhone模拟器把sqlite数据库保存在哪里

python - 如何安装 itertools 包?

python - 无法获取多个数据库的结果(SQL 工具)

python - 如何在 Plone 4.1.4 中向 intranet_workflow 添加更多自定义状态

python - 矢量到字符串,保存在文件中,然后再到矢量? Python

django - 这个QueryDict实例是不可变的

css - Django 静态文件未加载。修复 settings.py 以加载相对路径上的文件

python - Django : Limit records in database based on foreign key

android - 陈旧数据异常 : Attempted to access a cursor after it has been closed