Django-cms:'Settings'对象没有属性'SITE_ID'

时间:2017-07-14 13:11:40

标签: django django-cms

我想让我的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'

2 个答案:

答案 0 :(得分:0)

看起来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

答案 1 :(得分:0)

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

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