Django 从两个列表中动态填充模板

Django 从两个列表中动态填充模板,django,django-templates,python-2.x,Django,Django Templates,Python 2.x,我想从包含变量值的两个列表中动态填充模板 有人能告诉我,我怎样才能做到这一点: current_task_resources_types = ["image", "html"] current_task_resources_names = ["elephant.png", "index.html"] "task": [ {% for index in current_task_resources.length %} {"type": "{{ current_task_r

我想从包含变量值的两个列表中动态填充模板

有人能告诉我,我怎样才能做到这一点:

current_task_resources_types = ["image", "html"]
current_task_resources_names = ["elephant.png", "index.html"]

"task": [
    {% for index in current_task_resources.length %}
        {"type": "{{ current_task_resources_types.index }}", "url": "{{ current_task_resources_names.index }}"},
    {% endfor %}
],
您可以在视图中查看列表

current_task_resources = zip(current_task_resources_types, current_task_resources_names)
然后循环浏览模板中的压缩列表

"task": [
    {% for type, name in current_task_resources %}
        {"type": "{{ type }}", "url": "{{ names }}"},
    {% endfor %}
]
在Python2中,如果列表很长,
itertools.izip
可能会提高性能