Ticket #9977: csrf_templatetag.diff

File csrf_templatetag.diff, 1.3 KB (added by Bob Thomas, 16 years ago)
  • django/contrib/csrf/templatetags/csrf.py

     
     1from django import template
     2from django.contrib.csrf.middleware import _make_token
     3
     4register = template.Library()
     5
     6class CsrfTokenNode(template.Node):
     7    def render(self, context):
     8        return "<div style='display:none;'><input type='hidden' id='csrfmiddlewaretoken' name='csrfmiddlewaretoken' value='" + context['csrf_token'] + "' /></div>"
     9
     10@register.tag
     11def csrf_token(parser, token):
     12    return CsrfTokenNode()
  • django/contrib/csrf/context_processors.py

     
     1from django.contrib.csrf.middleware import _make_token
     2
     3def csrf(request):
     4    if hasattr(request, 'session'):
     5        return {'csrf_token': _make_token(request.session.session_key)}
     6    else:
     7        return {}
Back to Top