InoriS
InoriS

Reputation: 43

Usage of {{ and {% in django?

In views.py I passed 'key_tp_list': tb_list,'key_tb_list': tb_list. Their type is dictionay list. Then in my html, I wrote :

{% for i in range(key_tp_length) %}
    <li>{{ key_tp_list[i].eid }} | {{ dict.user }} | {{ dict.start_time }} | {{ dict.note }}</li>
{% endfor %}

And it turned out to have 2 errors : I can't use a range(key_tp_length) in {% %}, neither I can use a key_tp_list[i] in {{ }}.

How can I fix this?

Upvotes: 0

Views: 52

Answers (1)

AKX
AKX

Reputation: 169184

You can't use complex expressions in Django {{ }} tags, but assuming key_tp_length is the length of key_tp_list, you can do:

    {% for item in key_tp_list %}
        <li>{{ item.eid }} | {{ item.user }} | {{ item.start_time }} | {{ item.note }}</li>
    {% endfor %}

Upvotes: 5

Related Questions