如何在主页 wagtail 上添加联系表单
How add a contact form on homepage wagtail
你好,我是 wagtail 和 Django 的初学者,在我的设计中,联系表格在主页上,我只为初学者创建了一个教程,在专门的联系页面中包含一个联系表格,我如何在我的主页?
我的模型主页如下所示:
class HomePage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [ FieldPanel('description', classname="full") ]
他们在教程中使用了这个模型:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
class FormPage(AbstractEmailForm):
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()
但这会创建另一个我不需要的页面。如何在我的主页上添加表格?
非常感谢。
(未测试)而不是教程中的这个:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
做:
class FormField(AbstractFormField):
page = ParentalKey('HomePage', related_name='custom_form_fields')
然后将 HomePage
定义更改为:
class HomePage(AbstractEmailForm, Page):
description = models.CharField(max_length=255, blank=True,)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + Page.content_panels + [
FieldPanel('description', classname="full"),
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()
你好,我是 wagtail 和 Django 的初学者,在我的设计中,联系表格在主页上,我只为初学者创建了一个教程,在专门的联系页面中包含一个联系表格,我如何在我的主页?
我的模型主页如下所示:
class HomePage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [ FieldPanel('description', classname="full") ]
他们在教程中使用了这个模型:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
class FormPage(AbstractEmailForm):
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()
但这会创建另一个我不需要的页面。如何在我的主页上添加表格?
非常感谢。
(未测试)而不是教程中的这个:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
做:
class FormField(AbstractFormField):
page = ParentalKey('HomePage', related_name='custom_form_fields')
然后将 HomePage
定义更改为:
class HomePage(AbstractEmailForm, Page):
description = models.CharField(max_length=255, blank=True,)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + Page.content_panels + [
FieldPanel('description', classname="full"),
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()