wagtail内容流提供标准内容类型的流字段。
wagtailcontentstream的Python项目详细描述
Wagtail内容流
一个带有名为body
的wagtail streamfield的抽象django模型,其中包含我经常使用的多个块。有人认为:文本块中只允许很少的html,这迫使作者创建结构化数据。流块中包括以下块,ContentStreamBlock
:
- 航向
- 段落
- 标题图像
- 嵌入
- 表
- 代码块
辅助streamblockContentStreamBlockWithRawCode
还提供了用于注入html、js和css代码的附加块。小心使用,因为这真的可以炸掉你的标记,是一个潜在的代码注入点!
开箱即用提供了三种页面类型
示例用法
您需要将wagtailcodeblock
添加到INSTALLED_APPS
django设置中。
基本用法:标题字段和内容流
首先,在models.py
:
fromwagtailcontentstream.modelsimportContentStreamPage,SectionContentStreamPage,ContentStreamPageWithRawCodeclassStandardPage(ContentStreamPage):passclassSectionStandardPage(SectionContentStreamPage):passclassStandardPageWithRawCode(ContentStreamPageWithRawCode):pass
然后在您的模板中:
{%loadwagtailcore_tags%}<h2>{{page.title}}</h2>{%include_blockpage.body%}