this is my views.py :
a=[{'s':'sss'},{'s':'wwww'},{'s':'ssaawdw'},{'s':'qqqww'}]
def main(request, template_name='index.html'):
context ={
'a':a,
}
return render_to_response(template_name, context)
this is my filter :
def return_next_element(l开发者_运维问答ist, index):
if(index<len(list)-1):
return list[index+1]
else :
return 0
register.filter('return_next_element',return_next_element)
and this is my template :
{% load myfilters %}
{% for i in a %}
{{ i }}ww{{ (a|return_element:forloop.counter0).s }}
{% endfor %}
but , this cant get the a.s ,
so what can i do ,
thanks
updated
this is not a same question , because i will use like this :
a|return_element:forloop.counter0).s|other filter
For your situation, I'd suggest doing the following:
{% for dictionary in a %}
{% for key, value in dictionary.iteritems %}
{{ key }}ww{{ value }}
{% endfor %}
{% endfor %}
But to answer your question, use the with
tag.
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#with
{% with a|return_element:forloop.counter0 as result %}
{{ result|other_filter }}
{% endwith %}
精彩评论