代码之家  ›  专栏  ›  技术社区  ›  khashashin

将基于Django的插件集成到wagtail中

  •  0
  • khashashin  · 技术社区  · 7 年前

    例如,我试图将两个非常有用的Django插件(widget)集成到我的项目中,在这两种情况下,当涉及到自定义和将代码插入设置时,我都遇到了问题。py公司

    在这两种情况下,我都必须 customize code 但我们没有设置。py在wagtail中,如果我尝试输入以下代码:

    COUNTRIES_OVERRIDE = {
       'XZ': _('Tibet')
    }
    

    (env) C:\Users\xakep\Documents\GitHub\database\blemmy>manage.py runserver
    Traceback (most recent call last):
        File "C:\Users\xakep\Documents\GitHub\database\blemmy\manage.py", 
            line 10, in <module> execute_from_command_line(sys.argv)
        File "C:\Python36\lib\site-packages\django\core\management\__init__.py", 
            line 363, in execute_from_command_line utility.execute()
        File "C:\Python36\lib\site-packages\django\core\management\__init__.py", 
            line 307, in execute settings.INSTALLED_APPS
        File "C:\Python36\lib\site-packages\django\conf\__init__.py", line 56, 
            in__getattr__self._setup(name)
        File "C:\Python36\lib\site-packages\django\conf\__init__.py", line 41, 
            in _setup self._wrapped = Settings(settings_module)
        File "C:\Python36\lib\site-packages\django\conf\__init__.py", line 110, 
            in__init__ mod = importlib.import_module(self.SETTINGS_MODULE)
        File "C:\Python36\lib\importlib\__init__.py", line 126, in import_module
            return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 978, in _gcd_import
        File "<frozen importlib._bootstrap>", line 961, in _find_and_load
        File "<frozen importlib._bootstrap>", line 950, in 
            _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 678, in exec_module
        File "<frozen importlib._bootstrap>", line 205, in 
            _call_with_frames_removed
        File "C:\Users\xakep\Documents\GitHub\database\blemmy\blemmy\settings\
            __init__.py", line 1, in <module> from .dev import *
        File "C:\Users\xakep\Documents\GitHub\database\blemmy\blemmy\settings\
            dev.py", line 2, in <module> from .base import *
        File "C:\Users\xakep\Documents\GitHub\database\blemmy\blemmy\settings\
            base.py", line 112, in <module> 'XZ': _('Tibet')
        NameError: name '_' is not defined
    

    如果你能帮我(解释)如何在wagtail中使用类似的项目,我有很多好主意=)

    1 回复  |  直到 7 年前
        1
  •  0
  •   gasman    7 年前

    base.py 是这样设置的正确位置。在Wagtail项目结构中,设置被分解为dev.py(用于仅在开发环境中使用的设置)、production。py(仅用于生产中使用的设置)和base。py(两者通用),如下所述: http://docs.wagtail.io/en/v1.11.1/reference/project_template.html#django-settings

    这个 name '_' is not defined _ 是将字符串标记为可翻译的标准约定,如Django文档中所述: https://docs.djangoproject.com/en/1.11/topics/i18n/translation/

    要修复此问题,请在设置文件的顶部添加以下行:

    from django.utils.translation import ugettext_lazy as _