0
我是Django 1.7使用此代碼呈現視圖。在這裏,我正在渲染一個名爲frame.html
的html模板並傳遞上下文。CSRF令牌沒有插入到模板中
from django.template import Context
from django.template import Template
from django.shortcuts import render
from django.http import HttpResponse
def frame(request):
if request.GET.get('qid'):
qid = request.GET['qid']
displayQuestion = questions.objects.filter(questionSetId=qid)[0].Questions
questionJSON = json.loads(displayQuestion)
template = Template('frame.html')
context = Context({'qid':qid,'questionData':questionJSON})
return render(request,'frame.html',context)
else:
return views.products(request)
在我的模板frame.html
有一個形式,我usinf內部的{%csrf_token%}
標籤。這是代碼。
<form action="/submit" method="POST" id="responseform">
{% csrf_token %}
<input type="hidden" id="questionID" name="questionID" value="{{qid}}">
<input type="hidden" id="studentResponse" name="responses" value="">
</form>
我的問題是,儘管使用csrf_token
標籤,我收到一條錯誤消息CSRF token missing or incorrect
。請檢查這個錯誤。謝謝
我的無知,只有我的無知。真棒! – nitroman