【问题标题】:How can I use WYSIWYG editor in Wagtail CMS?如何在 Wagtail CMS 中使用 WYSIWYG 编辑器?
【发布时间】:2019-01-07 18:02:46
【问题描述】:

我正在尝试将 Wagtail CMS 与我现有的 Django 项目集成。除了this basic installation,我还创建了一个名为wagtail_hooks.py 的文件。到目前为止一切都很好,但我需要在 Wagtail CMS 上使用 WYSIWYG 编辑器。有没有办法访问 Wagtail 的 models.py,以便我可以在模型级别使用第三方所见即所得编辑器?

MY_APP/wagtail_hooks.py

from wagtail.contrib.modeladmin.options import (
    ModelAdmin, modeladmin_register)
from .models import Store


class StoreAdmin(ModelAdmin):
    model = Store
    menu_label = 'Store'  # ditch this to use verbose_name_plural from model
    menu_icon = 'doc-full'  # change as required
    menu_order = 10  # will put in 3rd place (000 being 1st, 100 2nd)
    add_to_settings_menu = False  # or True to add your model to the Settings sub-menu
    exclude_from_explorer = False  # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ['id', 'status', 'typ', 'businessName',]
    search_fields = ('businessName', 'created_by__username',)


# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(StoreAdmin)

【问题讨论】:

  • 为什么要使用第三方所见即所得?我在我的网站上使用 Wagtail 的全部原因是它内置了一个可以自定义的功能,并且它支持图像。
  • 我想与所见即所得一起使用的模型是 TextField()。所见即所得是应该自动应用还是我应该额外配置一些东西?

标签: django wagtail


【解决方案1】:

Wagtail 带有一个出色的所见即所得编辑器 Draftail,它基于 DraftJS。它具有高度可扩展性:

http://docs.wagtail.io/en/v2.4/advanced_topics/customisation/extending_draftail.html

要使用它,您可以将模型更改为使用wagtail.core.fields.RichTextField 而不是TextField

还有其他几个所见即所得的编辑器可用,例如,您仍然可以使用具有此设置的旧编辑器:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
    }
}

祝你好运!

【讨论】:

  • 呃,您添加的代码 sn-p 没有显示在移动设备上。如果此答案不适用于您尝试执行的 ModelAdmin,我们深表歉意。
猜你喜欢
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 2013-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多