在mako中,我们可以编写以下内容来生成动态html
<% months=['Jan','Feb', .. 'Dec'] %>
<% weeks=['Mon','Tue',..'Sun'] %>
% for m in months:
% for w in weeks:
${m} ${w}
% endfor
% endfor
在django(django模板)中没有来自上下文变量的列表,推荐的编码是否相同?
答案 0 :(得分:0)
我在templatetags / my_filters.py
下使用了django自定义模板标记过滤器from django import template
register = template.Library()
@register.assignment_tag
def weekdays():
return ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
并在模板中
{% load my_filters %}
{% weekdays as w %}
{% for i in w %}
<option value="{{forloop.counter0}}">{{i}}</option>
{% endfor %}