Django:{%csrf_token%}不断返回403 Forbidden错误

时间:2019-02-05 05:54:59

标签: python django django-csrf

我有一个尝试提交的表单,但是每当我单击“提交”按钮时,Django就会将我置于“ 403禁止页面”错误中。我不知道如何解决这个问题。请帮忙。这是通过使用实现CSS来完成的。

page.html:

<form action="/present/" method="POST">
    {% csrf_token %} 
    <p>
        <input type="checkbox" id="completed" name="completed" />  
        <label for="completed">Present</label>
    </p>
        <input class="waves-effect waves-light btn" type='submit'/>

</form>

views.py:

def present(request):
    completed = request.GET.get('pre')
    if request.POST.get('completed', '') == 'on':
        print("Succes!")
    else:
        print("Nope")
    #above coode doesn't work either for detecting whether or not the 
checkbox was selected.
    return render(request, 'main/test.html')

1 个答案:

答案 0 :(得分:-1)

它将起作用,只需刷新页面或关闭选项卡即可。