【问题标题】:In wagtail , Streamforms is not rendering the content of the form在 wagtail 中,Streamforms 不会呈现表单的内容
【发布时间】:2018-07-07 21:17:54
【问题描述】:

我已经安装了 wagtail Streamforms 包最新版本和 wagtail 2.0 ,但是当我使用它创建表单并且表单内容未使用默认表单模板显示并且当我定义自定义模板“streamforms/form_block.html”时仍然它没有显示的表单内容。我已经定义了我在我的base.py文件中使用的模板,如文档中所述。

WAGTAILSTREAMFORMS_FORM_TEMPLATES = ( ('streamforms/form_block.html', '默认表单模板'), )

但是在管理面板->创建表单时的Streamforms,在模板选择器字段中它只显示“默认表单模板”

我已经在流域中的 models.py 中定义了它,并且我自己定义了模板来显示它仍然没有呈现的内容 类标准页面(页面):

class StandardPage(Page):
    introduction = models.TextField(
        help_text='Text to describe the page',
        blank=True)
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
    )
    video_url = models.URLField(
        null=True,
        blank=True
    )
    body = StreamField([
        (
            'main_content',
            blocks.ListBlock(BaseStreamBlock(), label='content')
        ),
        (
            'form',
            blocks.ListBlock(WagtailFormBlock(), label='create form')
        )
    ,],
        blank=True,
        null=True,
        verbose_name="Standard Page"
    )

    content_panels = Page.content_panels + [
        FieldPanel('introduction', classname="full"),
        ImageChooserPanel('image'),
        FieldPanel('video_url'),
        StreamFieldPanel('body'),
    ]

    @property
    def standard_page(self):
        return self.get_parent().specific

这是我的“Standard_Page.html”模板

    {% extends "base.html" %}
{% load wagtailcore_tags wagtailtrans_tags streamforms_tags wagtailimages_tags homeapp_tags%}



 {% block content%}


{% include "base/include/header.html" %}
    <div class="container">
{{ page.introduction }}
     {{ page.image }}

        <div class="row">
            <div class="col-md-7">
               {% for block in page.body %}
                {{ block}}
{% endfor %}
            </div>

        </div>
        </div>
{% endblock  %}

我做错了什么?

【问题讨论】:

  • 请添加完整的模型。面板在哪里?
  • 我已经编辑了问题。现在,您可以看到我定义的完整模型。任何帮助,我需要做什么。
  • 我已经重新格式化了你的 Python 代码。您是否遵循 WagtailFormBlock 上的文档。这就是你应该如何使用它wagtailformblocks.readthedocs.io/en/latest/usage.html
  • 先生,实际上我使用的是包,wagtailstreamforms 并且我按照其中给出的说明进行操作。

标签: wagtail wagtail-streamfield


【解决方案1】:

假设您在上面放置的是您的实际设置:

WAGTAILSTREAMFORMS_FORM_TEMPLATES = (
    ('streamforms/form_block.html', 'Default Form Template'),
)

这仅用于填充表单中可用模板的下拉列表。您所设置的正是设置中的默认设置。如果您想覆盖包中的默认模板,您只需确保位于您自己代码中路径streamforms/form_block.html 上的模板位于INSTALLED_APPS 中出现在 wagtailstreamforms 之前的应用程序中。 Django 将首先看到您的模板并进行渲染。

如果您想为默认提供额外的模板,只需进行设置:

WAGTAILSTREAMFORMS_FORM_TEMPLATES = (
    ('streamforms/form_block.html', 'Default Form Template'),
    ('example/forms/another_form_block.html', 'My Custom Template'),
)

然后创建一个模板“example/forms/another_form_block.html”,就像http://wagtailstreamforms.readthedocs.io/en/latest/templates.html#templates 中的示例一样。然后,您将有两种模板可供选择。包装内的那个和你自己的。

希望这会有所帮助。

【讨论】:

  • 你能帮我如何获取表单显示的内容。它不会在页面上呈现它包含的表单的字段。做,我必须把这个{% load streamforms_tags % } {% streamforms_form slug="form-slug" reference="some-very-unique-reference" action="." %} 到我的模板代码中。
  • 您如何在前端模板中迭代流字段主体?您是否将创建的表单视为在流字段中选择的选项?
  • 你的代码是公开的吗?有大约 100 个问题?
  • 我编辑了我的标准页面类并将我的模板代码放在上面的问题中,你可以看到它。是的,我可以在标准页面的管理员中看到字段表单,现在我什至在尝试之后使用默认模板,它不显示表单
  • 我在标准页面的管理面板中将表单操作留空。是这个原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 2013-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多