我正在使用 django 1.5.1,我必须在每个 POST 上使用 {% csrf_token %} 才能工作。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 对我不起作用。我很困惑。