Django の csrf_token について - 混沌脳内
毎回ハマる。 Howtoを書くと、 viewに
インポートは
from django.views.decorators.csrf import csrf_protect from django.template import RequestContext
アクションに
@csrf_protect def my_action(request, hoge):
render_to_responseしてた部分は
template_dict = { 'foo': 0, 'bar': 1, } # レンダリング response = render_to_response( template, template_dict )
から、
template_dict = { 'foo': 0, 'bar': 1, } ctxt = RequestContext(request, template_dict) # レンダリング response = render_to_response( template, ctxt )
のように、RequestContextを挟む。