我無法在Django中查看模板中的發佈數據。表單數據不會傳遞到Django中查看
從Django中的錯誤信息是:
「CSRF驗證失敗的請求中止。」
這裏是我的代碼:
提交形式:
<form action="/submitted/" method="post">
{% csrf_token %}
*.... User input some data ....*
</form>
結果頁面(test.html中):
<body>
{{ passed_dict }}
</body>
view.py
from django.core.context_processors import csrf
from django.template import RequestContext
def submitted(request):
passed_dict = {}
if request.method == 'POST':
passed_dict.update(csrf(request))
''' get the data from post and do things '''
else:
passed_dict['result'] = 'this_is_result'
## no matter what thing did, back to the original page.
return render(request, 'group_detail.html', passed_dict)
我按照Django網站上的設置指南,但仍然無法正常工作。
我錯過了什麼嗎?
可以在'passed_dict.update(csrf(request))'之後打印passed_dict'。你看到了什麼? –
「CSRF驗證失敗,請求中止。」 –