render lists on fly using django templates -
in mako, can write following generate dynamic html
<% months=['jan','feb', .. 'dec'] %> <% weeks=['mon','tue',..'sun'] %> % m in months: % w in weeks: ${m} ${w} % endfor % endfor
whats recommended coding same in django(django templates) without lists coming context variables?
i've used django custom template tag filters under templatetags/my_filters.py
from django import template register = template.library() @register.assignment_tag def weekdays(): return ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
and in template
{% load my_filters %} {% weekdays w %} {% in w %} <option value="{{forloop.counter0}}">{{i}}</option> {% endfor %}
Comments
Post a Comment