[Answered ]-How do I access a python list from a django templatetag?

-1👍

Since writing complex templatetags is not an easy task (well documented though) i would take {% with %} tag source and adapt it for my needs, so it looks like

{% get_content_list as content %
{% for items in content %} 
       <h2>{{items.title}}</h2> 
{% endfor %}`

3👍

If the list is in a python variable X, then add it to the template context context['X'] = X and then you can do

{% for items in X %}
       {{ items.title }}
{% endfor %}

A template tag is designed to render output, so won’t provide an iterable list for you to use. But you don’t need that as the normal context + for loop are fine.

Leave a comment