我正在对CBV Formview进行快速测试。但是由于某些原因,表格不会提交,我看不清楚是为了找出原因。没有显示错误,当我点击提交时没有任何反应并且它没有重定向到成功URL或打印出测试消息。
形式:
class EmailTestForm(forms.Form):
email = forms.EmailField()
查看:
class EmailTestFormView(FormView):
form_class = EmailTestForm
template_name = "site/test_email.html"
success_url = "/signup"
def form_valid(self, form):
print('form is good')
模板:
{% extends "site/signup.html" %}
{% load crispy_forms_tags %}
{% block inner %}
<form action="" method="post" >{% csrf_token %}
{% crispy form %}
<input id="submit" class="btn btn-block btn-cta-primary" type="submit"/>
</form>
{% endblock inner %}
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^signup/$', views.signup_view, name="signup"),
url(r'^emailtest/$', views.EmailTestFormView.as_view(), name="email_test"),
]
答案 0 :(得分:0)
这是因为使用cripsy表单来呈现表单,这会在呈现表单时自动插入<form>
标记。
来自crpsy形式的文档:
form_tag = True
It specifies if <form></form> tags should be rendered when using a Layout. If set to False it renders the form without the <form></form> tags. Defaults to True.