一个View(ViewA)生成一个带有context(contextA)的模板。
ViewA从DetailView或ListView继承。
在ViewA中,我有一个表单(联系表单),该表单在提交时会将数据发送到另一个继承自FormView的View(ViewB)。
class ViewA(DetailView):
model = Item
class ViewB(FormView):
def get_success_url(self):
send_contact__email(sender_email, receiver_email, title, item, message,location)
在表单中,我既要有可见字段,又要有多个HiddenInput字段,这些字段将contextA数据发送到ViewB,基本上有关页面的信息是用户访问了联系表单。
class ContactForm(forms.Form):
title = forms.CharField(max_lenght=255)
message = forms.CharField()
item = forms.HiddenInput()
location = forms.HiddenInput()
receiver_email = forms.EmailField()
sender_mail = forms.EmailField()
<div class="modal">
<form action="{{ item.contact_form_viewb }}" method="post">
{% csrf_token %}
....... # here to set fields
with value like {{ item.title}}
....... # here to set fields
<input type="submit" value="Send"/>
<button type="button" Cancel</button>
</form>
</div>
考虑到是DetailView而不是Create / Update视图,如何将表单集成到ViewA中?
如何在模板中设置HiddenInput将数据发送到ViewB?