简体   繁体   中英

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?

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM