Ticket #9977: csrf_templatetag.diff
File csrf_templatetag.diff, 1.3 KB (added by , 16 years ago) |
---|
-
django/contrib/csrf/templatetags/csrf.py
1 from django import template 2 from django.contrib.csrf.middleware import _make_token 3 4 register = template.Library() 5 6 class 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 11 def csrf_token(parser, token): 12 return CsrfTokenNode() -
django/contrib/csrf/context_processors.py
1 from django.contrib.csrf.middleware import _make_token 2 3 def csrf(request): 4 if hasattr(request, 'session'): 5 return {'csrf_token': _make_token(request.session.session_key)} 6 else: 7 return {}