Daily Shaarli

All links of one day in a single page.

January 18, 2008

Django snippets: Create new variables in templates
Account Sign-in: 8 Design Mistakes to Avoid
Django snippets: "for" template tag with support for "else" if array is empty

This is a customized version of the default for template tag which takes an optional {% else %} clause that will be displayed if the given array is empty.

from django.template import *

t1 = Template("""
{% load mytags %}
{% for athlete in athlete_list %}
{{ athlete }}
{% else %}
No athlete in list!
{% endfor %}
""")
c1 = Context(
{'athlete_list':
['me ...