1

I'm a little new to Django, and I'm trying to create a login form for the users of my site. I'm using Django's user app. i've created a simple form with username and password fields as follows:

<form id='login-form' action="login" method="post">
<div class='login-field'><input type='text' name='username' placeholder=' Username'></div>
<div class='password-field'><input type='password' name='password' placeholder=' Password'spellcheck='false'></div> <br />
<input type='submit' value='SUBMIT' spellcheck='false'>
</form>

the problem i get when pressing the submit button is:

CSRF verification failed. Request aborted

I've looked through all the solutions to similar questions on this site and others and still haven't been able to solve the problem, any suggestions?

4

2 回答 2

4

您需要模板中标签{% csrf_token %}内的某个位置。<form>

有关更多信息,请参阅有关跨站点请求伪造的 Django 文档

于 2011-05-25T14:26:02.620 回答
1

查看文档中的跨站点请求伪造保护

基本上你需要{% csrf_token %}在表单标签之后。

于 2011-05-25T14:26:43.477 回答