Skip to content

Commit

Permalink
Rewrote csrf_token tag to use the code of Django's own tag, rather th…
Browse files Browse the repository at this point in the history
…an duplicating it.
  • Loading branch information
miracle2k committed Mar 10, 2010
1 parent 38e9d10 commit 70e8732
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions coffin/template/defaulttags.py
Expand Up @@ -370,19 +370,8 @@ def parse(self, parser):
]).set_lineno(lineno)

def _render(self, csrf_token):
if csrf_token:
if csrf_token == 'NOTPROVIDED':
return Markup(u"")
else:
return Markup(u"<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='%s' /></div>" % (csrf_token))
else:
# It's very probable that the token is missing because of
# misconfiguration, so we raise a warning
from django.conf import settings
if settings.DEBUG:
import warnings
warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.")
return u''
from django.template.defaulttags import CsrfTokenNode
return Markup(CsrfTokenNode().render({'csrf_token': csrf_token}))


# nicer import names
Expand Down

0 comments on commit 70e8732

Please sign in to comment.