Login

Snippets by stefanp

Snippet List

dict recurse template tag for django

Based on http://www.djangosnippets.org/snippets/592/, a simplified recurse template tag that will explore dict and list objects. Useful and straightforward for JSON documents (for instance from couchdb :p). Actual usage example: {% recursedict mydictionary %} <ul> {% loop %} <li>{% if key %}<b>{{ key }}</b>:&nbsp;{% endif %}{% value %}</li> {% endloop %} </ul> {% endrecurse %} The main tag syntax is "recursedict var" where var is your dictionary name. The "key" property will contain the current key, or None if the current value comes from a list (in other words the list (a, b, c) is handled like a very hypothetical {None: a, None: b, None: c} dictionary.) {% value %} will output the current value, or recurse if the value is a list, tuple or dict.

  • template
  • templatetag
  • json
  • dict
  • resurse
Read More

stefanp has posted 1 snippet.