Casting to strings would make this example work. But will break in other cases:
dict((key, str(val)) for key, val in {'value': None}.items()) => <input value="None"> I don't want to say that this problem is impossible to solve without a "is" check in the templates, I only want to point out that this basic comparison that is very handy in python on many ocassions is not available in the template. And having something like this in core might just make the template language a bit rounder and nicer to use for pythonistas. · Gregor · 2014-04-11 7:44 GMT+02:00 Łukasz Rekucki <lreku...@gmail.com>: > On 11 April 2014 01:11, Gregor Müllegger <gre...@muellegger.de> wrote: > > Hi, > > > > thanks for your input. Unfortunatelly this would fail for int(0): > > Not if you encode all values to strings before passing to the > template, so it's "0" instead of 0. > > > > > {'value': 0} => <input value> > > > > Gregor > > > > > > 2014-04-10 11:41 GMT+02:00 Tino de Bruijn <tin...@gmail.com>: > > > >> Wouldn't this be easier?: > >> > >> {'required': "", 'name': 'fieldname'} => <input required > name="fieldname" > >> /> > >> > >> {% for name, value in attrs.items %} {{ name }}{% if value %}="{{ value > >> }}"{% endif %}{% endfor %} > >> > >> > >> Tino > >> > > -- > Łukasz Rekucki > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To post to this group, send email to django-developers@googlegroups.com. > Visit this group at http://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/CAEZs-EL%2BNqWuo-F6AkAWCBb5rn_7GKGXkfD35uyfF%2Bqbvss5Sw%40mail.gmail.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALjSGCNDMC1q7LhamQaf%3D9jEW0bXPn5gdpmDL88dVQgKsNb__Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.