我正在使用django 1.5.1,我必須在每個POST上使用{%csrf_token%}才能工作.RequestContext對我無效,這裏是我的設置,視圖代碼和模板代碼。django csrf令牌錯誤(RequestContext沒有工作)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
def show_rates(request, doc_id, template_name='rate.html'):
doc = get_object_or_404(Doctor, id=doc_id)
hos = doc.hospital
docts = hos.doctor_set.all()
page_title = doc.name
hos_name = hos.name
if request.method == "POST":
postdata = request.POST.copy()
form = AddToRateForm(postdata)
else:
form = AddToRateForm()
return render(request, template_name, locals())
<form method="POST" action=".">
{{ form.as_table }}
<div class="row-fluid">
<div class="span10">
</div>
<div class="span2">
<button class="btn btn-block btn-primary" type="submit">Rate</button>
</div>
</div>
</form>
RequestContext不適用於我。我很困惑。
你的模板是什麼樣的?你把令牌放在
你的意思是什麼都不起作用?你能提供一些模板並說出什麼不起作用嗎? – rjv 2013-05-06 15:41:57