3

in the mezzanine configuration docs, it says

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.

there are no examples showing how to do it, either on that page or in the django AppConfig.ready() page.

I created a 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/",
),

how do i import default.py into appconfig.ready() method manually please?

Sayse
  • 42,633
  • 14
  • 77
  • 146
fosi
  • 53
  • 8

1 Answers1

1

Import your default in ready() method. See below.

from django.apps import AppConfig
class ThemeConfig(AppConfig):
    name = 'theme'
    verbose_name = "Theme"
    def ready(self):
      from .default import *
green
  • 226
  • 2
  • 12
  • In Django 1.8.10, with Python 3.6, this solution is not working, I had this issue: `SyntaxError: import * only allowed at module level`. I replaced import by : `from .defaults import register_setting` and it worked perfectly – emilie zawadzki Dec 27 '18 at 11:24