Skip to content

Instantly share code, notes, and snippets.

@AnSavvides
Last active December 20, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnSavvides/d6725db951f75788e8eb to your computer and use it in GitHub Desktop.
Save AnSavvides/d6725db951f75788e8eb to your computer and use it in GitHub Desktop.
Django Templating: Variable named 'new' behaves unexpectedly
<p>
{% if not_new %}
{{not_new}}
{% endif %}
<p>
<p>
{% if new %}
{{new}}
{% endif %}
</p>
from django.template import loader, Context
# This one works as expected
template = loader.get_template('some_template.html')
context = Context({})
body = template.render(context)
# body now is: <p></p>
# This one does not work as expected.
buggy_template = loader.get_template('some_buggy_template.html')
buggy_context = Context({})
buggy_body = template.render(buggy_context)
# buggy_body now is: <p>[{}]</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment