我通过扩展WagtailFormBlock
下面给出的方法创建了 wagtail FreeForm。我可以使用wagtail admin interface
.
文件名:blocks.py
from wagtailformblocks.blocks import WagtailFormBlock
class MyForm(WagtailFormBlock):
class Meta:
app_label = 'demo'
这是models.py
我在其中创建页面并将表单分配给该页面的文件。
文件名:models.py
from wagtail.wagtailcore.models import Page
from wagtailformblocks.models import BaseForm
from wagtail.wagtailcore.fields import StreamField
class FormType(BaseForm):
class Meta:
verbose_name = "Form Type"
class ImagePage(Page):
template = 'wagtail_demo/image_page.html'
content = StreamField([
('my_forms', MyForm()),
])
content_panels = Page.content_panels + [
StreamFieldPanel('content'),
]
这是我image_page.html
要呈现表单字段的页面。
文件名:image_page.html
{% load wagtailcore_tags %}
{% with blocks=self.content %}
{% for block in blocks %}
{{ block }}
{% endfor %}
{% endwith %}
它显示与此页面关联的表单的所有字段。我想单独访问关联表单的每个字段,(e.g.: field name etc.)
因为有时我需要使用 javascript 在提交按钮之前添加字段。我怎样才能做到这一点 ?