我正在创建一个简单的网站,它在localhost中工作。但是,当我部署我的网站时,它出现了错误。所以,我用谷歌搜索了我的代码不起作用的原因。然后,我意识到我的csrf东西有问题。但我真的不知道如何解决它。
首先,这是我的views.py
的一部分@csrf_protect
def register(request):
context = RequestContext(request)
registered = False
...
return render_to_response('mysite/register.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered},context)
这是我的register.html
<html>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="https://fonts.googleapis.com/css?family=Dosis&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<title>Regitser With PAM</title>
</head>
<body>
<h1>Register With PAM</h1>
{% if registered %}
<strong>Thank you for registering!</strong>
<a href = "/">Return to MainPage.</a><br />
{% else %}
<strong>Register here!</strong><br />
<form id = "user_form" method = "post" action = "/register/" enctype = "multipar/form-date">
{% csrf_token %}
{{ user_form.as_p }}
{{ profile_form.as_p}}
<input type = "submit" name "submit" value = "Register" />
</form>
{% endif %}
</body>
当我试图注册我自己的网站时,它总是想出了这个错误
Forbidden (403)
CSRF validation failed