Ticket #9977: 9977.diff

File 9977.diff, 1.3 KB (added by Rob Hudson <treborhudson@…>, 16 years ago)
  • new file django/contrib/csrf/context_processors.py

    diff --git a/django/contrib/csrf/context_processors.py b/django/contrib/csrf/context_processors.py
    new file mode 100644
    index 0000000..a896479
    - +  
     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 {}
  • new file django/contrib/csrf/templatetags/csrf.py

    diff --git a/django/contrib/csrf/templatetags/__init__.py b/django/contrib/csrf/templatetags/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/csrf/templatetags/csrf.py b/django/contrib/csrf/templatetags/csrf.py
    new file mode 100644
    index 0000000..a67ed72
    - +  
     1from django import template
     2
     3register = template.Library()
     4
     5class CsrfTokenNode(template.Node):
     6    def render(self, context):
     7        csrf_token = context.get('csrf_token', None)
     8        if csrf_token:
     9            return '<div style="display:none;">' + \
     10                   '<input type="hidden" name="csrfmiddlewaretoken" value="%s" /></div>' % (csrf_token)
     11        else:
     12            return ''
     13
     14@register.tag
     15def csrf_token(parser, token):
     16    return CsrfTokenNode()
Back to Top