python - 手动导入default.py到AppConfig ready()方法

标签 python django mezzanine

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 *

关于python - 手动导入default.py到AppConfig ready()方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34203680/

相关文章:

python - 从列表中传递参数

django - 将外部 django 应用程序 merge 到项目中并安全地进行本地更改的最佳方法

django - 将 URL 中的页码改为 "embed"的最佳方法是什么?

python - Heroku 上的夹层

python - 我该如何着手定制夹层墨盒商店/产品?

python - 连接使用循环生成的 pandas DataFrame

python - dreload() 和 autoreload 之间的关系/区别

python - watchdog(python) - 仅监视一种文件格式并忽略 'PatternMatchingEventHandler' 中的其他所有内容

python - 将迁移文件添加到存储库是好的做法吗?

python - 用博客条目替换 Twitter feed