手动导入default.py到AppConfig ready()方法
Importing default.py manually into AppConfig ready () method
在 mezzanine configuration docs 中显示
NOTE If you are using Django 1.7 or greater and your app is included in your INSTALLED_APPS as an AppConfig (eg authors.apps.MyCrazyConfig), Mezzanine won’t import your defaults.py automatically. Instead you must import it manually in your AppConfig’s ready() method.
在该页面或 django AppConfig.ready() 页面上都没有说明如何操作的示例。
我创建了一个 theme/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() 方法?
在 ready() 方法中导入默认值。见下文。
from django.apps import AppConfig
class ThemeConfig(AppConfig):
name = 'theme'
verbose_name = "Theme"
def ready(self):
from .default import *
在 mezzanine configuration docs 中显示
NOTE If you are using Django 1.7 or greater and your app is included in your INSTALLED_APPS as an AppConfig (eg authors.apps.MyCrazyConfig), Mezzanine won’t import your defaults.py automatically. Instead you must import it manually in your AppConfig’s ready() method.
在该页面或 django AppConfig.ready() 页面上都没有说明如何操作的示例。
我创建了一个 theme/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() 方法?
在 ready() 方法中导入默认值。见下文。
from django.apps import AppConfig
class ThemeConfig(AppConfig):
name = 'theme'
verbose_name = "Theme"
def ready(self):
from .default import *