我的代码未在Django中返回正确的视图

时间:2020-07-22 22:32:43

标签: django

查看

def compose(request):
    if request.method == "POST":
        if request.POST["confirmation"] is True:
            form = ComposeForm()
            return render(request,"practice/compose.html",{"form":form})
        else: 
            a = reverse("practice:index")
            return HttpResponseRedirect(a)

    else:
        a = reverse("practice:index")
        return HttpResponseRedirect(a)

表格

    <form action= "{% url 'practice:Compose' %} " method=post>
        Do you want to send emails to the following list?<br>
        <br>
        <button name="confirmation" type="submit" value="True">Yes</button>
        <button name="confirmation" type="submit" value="False">No</button>
    </form>

单击是按钮时,将显示索引页面。但是,它应该已经执行 return render(request,"practice/compose.html",{"form":form})

我怀疑我的if和else是否错了。请帮忙,谢谢!

1 个答案:

答案 0 :(得分:2)

否,"openapi": "3.0.1", ... // cutting out unrelated other stuff "/api/v1/test4/{Value2}": { "get": { "tags": [ ], "summary": "A sample GET", "parameters": [ { "name": "Value2", "in ": "path", "required": true, "schema": { "type": "string", "format": "" } }, , ], "responses": { "200": { "description": "Success", "content": { "application/json": { "$ref": "#/components/schemas/TestReply" } } } } } } } 检查is True是否引用了相同对象,但是这样的request.POST['confirmation']将字符串映射为 strings ,因此它永远不会是QueryDict。您可以使用True字符串进行匹配:

'True'
相关问题