9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

テンプレートで同時に変数をループさせる

Last updated at Posted at 2013-08-23

Pythonのzip関数みたいなやつをテンプレート内で実現させます。

    fist_name_list = ["一郎", "秀樹", "英雄"]
    second_name_list = ["鈴木", "松井", "野茂"]
    temp_list = []
    for i, _ in enumerate(fist_name_list):
        temp_list.append({
            'fist_name': fist_name_list[i],
            'second_name': fist_name_list[i],
        })

    render_to_response(
        'test.html', 
        {'temp_list': temp_list,}
     )
test.html
{% for fsname in temp_list %}
    {{fsname.fist_name}}
    {{fsname.second_name}}
{% endfor %}
9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?