Django-cms:“设置”对象没有属性“SITE_ID”

Posted

技术标签:

【中文标题】Django-cms:“设置”对象没有属性“SITE_ID”【英文标题】:Django-cms: 'Settings' object has no attribute 'SITE_ID' 【发布时间】:2017-12-19 14:39:45 【问题描述】:

我想启用我的 django-cms 实例来托管多个站点。 为此,我在管理面板中创建了两个不同的站点。

很遗憾,只显示了一个站点,因为我需要在项目设置中硬编码 SITE_ID。

根据https://github.com/django/django/pull/2460,这不再是强制设置。但是如果我删除它,我的 Django 1.10.7 实例会显示以下回溯:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/var/www/venv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/var/www/venv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 22, in ready
    self.module.autodiscover()
  File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/var/www/venv/lib/python3.5/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/var/www/venv/lib/python3.5/site-packages/cms/admin/__init__.py", line 2, in <module>
    import cms.admin.pageadmin
  File "/var/www/venv/lib/python3.5/site-packages/cms/admin/pageadmin.py", line 39, in <module>
    from cms.admin.forms import (
  File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 85, in <module>
    class PageForm(forms.ModelForm):
  File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 86, in PageForm
    language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
  File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 76, in get_language_tuple
    return [(lang['code'], lang['name']) for lang in get_languages(site_id)]
  File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 23, in get_languages
    site_id = get_site_id(site_id)
  File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
    return settings.SITE_ID
  File "/var/www/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 49, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SITE_ID'

【问题讨论】:

【参考方案1】:

看起来 Django CMS 需要 SITE_ID,它在回溯中

  File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
    return settings.SITE_ID

【讨论】:

感谢您的回复。我不确定这一点。代码(来自:/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py)看起来像,如果它不能得到它,它只是“最后一个选项”。跨度> 您好 Tobias,django CMS 需要 SITE_ID。【参考方案2】:

我以不同的方式解决问题。 我使用了插件djangocms-multisite。

我不知道这是否是最好的解决方案,但它确实有效。

【讨论】:

以上是关于Django-cms:“设置”对象没有属性“SITE_ID”的主要内容,如果未能解决你的问题,请参考以下文章

将现有的 django 应用程序与 django-cms 集成

选择起始页 django-cms

django django-cms 我没有成功访问应用程序的 urls.py

Django-CMS - 全球占位符?

将 if 语句添加到 django-cms 模板标签

Django-CMS apphooks 菜单和反向