Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created February 22, 2013 11:45
Show Gist options
  • Select an option

  • Save bmispelon/5012913 to your computer and use it in GitHub Desktop.

Select an option

Save bmispelon/5012913 to your computer and use it in GitHub Desktop.
Bug in django's forloop template compiling
from django.template import Template, Context
CONTEXT = Context({
's': '',
})
for tpl in [
'{% for x in s|add:"a b c" %}-{{ x }}{% endfor %}', # Doesn't work
'{% with v=s|add:"a b c" %}{% for x in v %}-{{ x }}{% endfor %}{% endwith %}',
'{% with v="a b c" %}{% for x in s|add:v %}-{{ x }}{% endfor %}{% endwith %}'
]:
s = Template(tpl).render(Context({'s': ''}))
assert s == u'-a- -b- -c'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment