diff --git a/django/contrib/csrf/context_processors.py b/django/contrib/csrf/context_processors.py
new file mode 100644
index 0000000..a896479
-
|
+
|
|
| 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 {} |
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
-
|
+
|
|
| 1 | from django import template |
| 2 | |
| 3 | register = template.Library() |
| 4 | |
| 5 | class 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 |
| 15 | def csrf_token(parser, token): |
| 16 | return CsrfTokenNode() |