Created
January 13, 2016 06:39
-
-
Save i5on9i/10d2b65649b2a3387c34 to your computer and use it in GitHub Desktop.
Simple Django TemplateView which can support csrf variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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