,它说
注意如果您使用的是Django 1.7或更高版本并且您的应用程序作为AppConfig包含在您的INSTALLED_APPS中(例如authors.apps.MyCrazyConfig),则Mezzanine将不会自动导入您的defaults.py。相反,您必须在AppConfig的ready()方法中手动导入它。
在该页面或django AppConfig.ready()页面中没有显示如何操作的示例。
我创建了一个主题/ app.py:
from django.apps import AppConfig
from .defaults import *
class ThemeConfig(AppConfig):
name = 'theme'
verbose_name = "Theme"
def ready(self):
default
the theme/defaulty.py is thus:
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _
from mezzanine.conf import register_setting
register_setting(
name="TEMPLATE_ACCESSIBLE_SETTINGS",
append=True,
default=("SOCIAL_LINK_FACEBOOK",
"SOCIAL_LINK_TWITTER",
"SOCIAL_LINK_INSTAGRAM",
"SOCIAL_GOOGLE-PLUS",
),
register_setting(
name="SOCIAL_LINK_FACEBOOK",
label=_("Facebook link"),
description=_("If present a Facebook icon linking here will be in the "
"header."),
editable=True,
default="https://facebook.com/mezzatheme",
),
register_setting(
name="SOCIAL_LINK_TWITTER",
label=_("Facebook link"),
description=_("If present a Facebook icon linking here will be in the "
"header."),
editable=True,
default="https://twitter.com/",
),
如何手动将default.py导入到appconfig.ready()方法中?
答案 0 :(得分:1)
在ready()方法中导入默认值。见下文。
from django.apps import AppConfig
class ThemeConfig(AppConfig):
name = 'theme'
verbose_name = "Theme"
def ready(self):
from .default import *