简体   繁体   English

无法获取Django CreateView保存

[英]Can't get Django CreateView to save

No doubt I'm missing something obvious here... 毫无疑问,我这里缺少明显的东西...

urls.py urls.py

url(r'^screening_add/$', ScreeningCreate.as_view(), name="screening_add"),

views.py views.py

class ScreeningCreate(CreateView):
    model = Screening

    def form_valid(self, form):
        return super(ScreeningCreate, self).form_valid(form)

screening_form.html screening_form.html

<form action="." method="post"> {{ form }}{% csrf_token %}
    <input type="submit" value="Submit">
</form>

This puts up the form with the Screening fields but on submit nothing happens. 这将在“筛选”字段中放置表单,但是在提交时没有任何反应。 I have a breakpoint at the return statement in form_valid and it doesn't get executed. 我在form_valid的return语句中有一个断点,但无法执行。 Removing the dot in action has no effect. 实际删除点无效。 What the heck am I missing? 我到底想念什么?

Is this is your whole views.py? 这是您的整个views.py吗? It should like this: 它应该像这样:

class ScreeningCreate(CreateView):
    model = Screening
    form_class = ScreeningForm

    def form_valid(self, form):
        return super(ScreeningCreate, self).form_valid(form)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM