Skip to content Skip to sidebar Skip to footer

Django - Calling List Or Dict Item Using A Variable In Template

I'm trying to call a dictionary or list object in a template using a variable in that template with no results. What I'm trying to is identical to this general python code: keylist

Solution 1:

The Django template language does not let you access dictionary keys and lists with variables. You could write a template tag to do this (see this question for example), but in your case there's a simpler alternative.

In your view, zip your tables and titles together

tables_and_titles = zip(tables, tabletiles)

Then loop through them together in your template.

{% for table, title in tables_and_titles %}
    {{ title }}
    <table>
    {{ table }}
    </table>
{% endfor %}

Post a Comment for "Django - Calling List Or Dict Item Using A Variable In Template"