Skip to content

Instantly share code, notes, and snippets.

@i5on9i
Created January 13, 2016 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i5on9i/10d2b65649b2a3387c34 to your computer and use it in GitHub Desktop.
Save i5on9i/10d2b65649b2a3387c34 to your computer and use it in GitHub Desktop.
Simple Django TemplateView which can support csrf variable
# coding=utf-8
from django.template.context_processors import csrf
from django.views.generic import TemplateView
class TemplateViewWithCsrf(TemplateView):
"""
This set the csrf which could be called by the Django template
"""
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context.update(csrf(request))
return self.render_to_response(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment