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

时间:2017-08-15 14:16:28

标签: django wagtail

当将最初为django构建的插件或小部件整合到wagtail中时,是否有人可以描述一般操作?对于新手用户来说,很难准确理解如何编辑代码以使其在wagtail cms中工作。 例如,我试图将两个非常有用的Django插件(小部件)集成到我的项目中,在两种情况下都会遇到问题,当涉及到自定义和插入settings.py

在这两种情况下,我都需要customize一些code,但我们没有令人烦恼的settings.py,如果生病,请尝试输入此代码:

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

in to base.py我收到错误:

(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 个答案:

答案 0 :(得分:0)

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错误与Wagtail无关 - 这是django-countries文档中遗漏的细节。定义一个名为_的函数是将字符串标记为可翻译的标准约定,在Django文档中有所描述:https://docs.djangoproject.com/en/1.11/topics/i18n/translation/

要解决此问题,请将以下行添加到设置文件的顶部:

from django.utils.translation import ugettext_lazy as _