简体   繁体   English

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

[英]Django: {% csrf_token %} keeps returning 403 Forbidden error

I have a form that I try to submit however whenever I click the submit button Django puts me into the 403 Forbidden page error. 我有一个要尝试提交的表单,但是每当我单击提交按钮时,Django会将我带入403禁止页面错误。 I have no clue how to fix this. 我不知道如何解决这个问题。 Please help. 请帮忙。 This is done using materialize CSS. 这是通过使用实现CSS来完成的。

page.html: 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: 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')

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

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

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