毫无疑问,我在这里遗漏了一些明显的东西......
urls.py
url(r'^screening_add/$', ScreeningCreate.as_view(), name="screening_add"),
views.py
class ScreeningCreate(CreateView):
model = Screening
def form_valid(self, form):
return super(ScreeningCreate, self).form_valid(form)
screening_form.html
<form action="." method="post"> {{ form }}{% csrf_token %}
<input type="submit" value="Submit">
</form>
这会将表单与屏幕字段一起显示,但在提交时没有任何反应。我在form_valid的return语句中有一个断点,它没有被执行。删除操作中的点无效。我错过了什么?
答案 0 :(得分:0)
这是你的整个views.py吗?它应该是这样的:
class ScreeningCreate(CreateView):
model = Screening
form_class = ScreeningForm
def form_valid(self, form):
return super(ScreeningCreate, self).form_valid(form)