跳转到主要内容

Wagtail内容流提供了一个标准内容类型的StreamField。

项目描述

Wagtail内容流

一个抽象的Django模型,包含一个名为body的Wagtail StreamField,包含我在日常使用中常用的多个块。这是针对需要编写包含代码示例的开发者设计的。它具有明确的观点:文本块中允许的HTML非常少,迫使作者创建结构化数据。以下块包含在ContentStreamBlock

  • 标题
  • 段落
  • 带标题的图片
  • 嵌入
  • 表格
  • 代码块

一个二级StreamBlock,ContentStreamBlockWithRawCode,还提供了一个用于注入HTML、JS和CSS代码的附加块。请谨慎使用,因为这可能会让你的标记膨胀,并且可能成为代码注入的潜在点!

提供了三种页面类型。

示例用法

您需要将 wagtailcodeblock 添加到您的 Django 设置 INSTALLED_APPS 中。

基本用法:标题字段和内容流

首先,在您的 models.py 中创建一个页面类型

from wagtailcontentstream.models import ContentStreamPage, SectionContentStreamPage, ContentStreamPageWithRawCode

class StandardPage(ContentStreamPage):
    pass

class SectionStandardPage(SectionContentStreamPage):
    pass

class StandardPageWithRawCode(ContentStreamPageWithRawCode):
    pass

然后在您的模板中

{% load wagtailcore_tags %}

<h2>{{ page.title }}</h2>
{% include_block page.body %}

扩展用法:添加更多字段

from django.conf import settings
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel
from wagtailcontentstream.models import ContentStreamPage


class StandardPage(ContentStreamPage):
    date = models.DateField("Post Date")
    authors = models.ManyToManyField(settings.AUTH_USER_MODEL)

    content_panels = [
        FieldPanel('date'),
        FieldPanel('authors'),
    ] + ContentStreamPage.content_panels

发行说明 & 贡献者

  • 感谢我们杰出的贡献者
  • 发行说明可在GitHub上找到此处

项目负责人

项目详情


下载文件

为您的平台下载文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

wagtailcontentstream-1.0.0.tar.gz (7.4 kB 查看哈希)

上传时间 源代码

构建分发

wagtailcontentstream-1.0.0-py3-none-any.whl (7.8 kB 查看哈希)

上传时间 Python 3

支持者