WagtailMedia是Wagtail CMS的媒体编辑器集成。
django_wagtailmedium的Python项目详细描述
WagtailMedia是Wagtail CMS的媒体编辑器集成。
note:有更详细的.codestory格式的文档,以及要处理的示例项目。
安装
从pip安装:
pip install django-wagtailmedium
将wagtailmedium添加到应用程序中:
INSTALLED_APPS = [ ... 'wagtailmedium', ]
三。将wagtailmedium小部件添加到“wagtailadmin”富文本编辑器`(由wagtail实现,尚未记录)
WAGTAILADMIN_RICH_TEXT_EDITORS = { 'default': { 'WIDGET': 'wagtail.wagtailadmin.rich_text.HalloRichTextArea' }, 'medium': { 'WIDGET': 'wagtailmedium.rich_text.MediumRichTextArea', 'OPTIONS': { 'custom_buttons': { 'code': { 'contentDefault': '<b>Code</b>', 'contentFA': '<i class="fa fa-code"></i>', 'tag': 'code', 'className': 'code', # optional }, 'test': { 'contentDefault': '<b>Test</b>', 'contentFA': '<i class="fa fa-code"></i>', 'tag': 'span', 'className': 'test', # optional }, }, 'medium': { # https://github.com/yabwe/medium-editor#options-example # 'buttonLabels': 'fontawesome', 'toolbar': { 'buttons': [ # https://github.com/yabwe/medium-editor#all-buttons 'bold', 'italic', 'underline', 'code', 'test', 'link', 'linkdoc', 'h2', 'h3', 'orderedlist', 'unorderedlist', 'strikethrough' ] }, }, }, }, }
- register whitelister元素规则
这个wagtailhook定义了在富文本区域中允许哪些html元素。
wagtail_hooks.py:
from wagtail.wagtailcore import hooks from wagtail.wagtailcore.whitelist import attribute_rule, allow_without_attributes # http://docs.wagtail.io/en/v1.7/reference/hooks.html#construct-whitelister-element-rules @hooks.register('construct_whitelister_element_rules') # #7bFcf# def whitelister_element_rules(): return { 'u': allow_without_attributes, 'span': attribute_rule({'class': True}), 'code': allow_without_attributes, 'blockquote': allow_without_attributes, }
- 在模型的richtextfield中使用wagtailmedium
models.py:
from wagtail.wagtailcore.models import Page, StreamField, RichTextField class HomePage(Page): # a default, Hallo editor hallo = RichTextField(blank=True) # a medium editor medium = RichTextField(editor='medium', blank=True)