[Fixed]-Django CSRF token won't show

22👍

You need to pass the RequestContext in your render_to_response for the context processors to actually be run.

 from django.template import RequestContext

 context = {}
 return render_to_response('my_template.html',
                           context,
                           context_instance=RequestContext(request))

the new render shortcut (django 1.3+) will do it for you:

 from django.shortcuts import render

 context = {}
 return render(request, 'my_template.html', context)

5👍

While there is a checked answer, I want to point out that writing context_instance.... gets really annoying. I find this useful…especially with forms

context.update(csrf(request))

Leave a comment