How to iterate through a list of dictionaries in Jinja template?

后端 未结 5 1364
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 20:00

I tried:

list1 = [{\"username\": \"abhi\", \"pass\": 2087}]
return render_template(\"file_output.html\", list1=list1)

In the template:

5条回答
  •  遥遥无期
    2020-12-07 20:21

    **get id from dic value. I got the result.try the below code**
    get_abstracts = s.get_abstracts(session_id)
        sessions = get_abstracts['sessions']
        abs = {}
        for a in get_abstracts['abstracts']:
            a_session_id = a['session_id']
            abs.setdefault(a_session_id,[]).append(a)
        authors = {}
        # print('authors')
        # print(get_abstracts['authors'])
        for au in get_abstracts['authors']: 
            # print(au)
            au_abs_id = au['abs_id']
            authors.setdefault(au_abs_id,[]).append(au)
     **In jinja template**
    {% for s in sessions %}
              

    Session : {{ s.session_title}} - Hall : {{ s.session_hall}}

    {% for a in abs[s.session_id] %}

    Chief Author : Dr. {{ a.full_name }}

    {% for au in authors[a.abs_id] %}

    {{ au.role }} : Dr.{{ au.full_name }}

    {% endfor %} {% endfor %} {% endfor %}

提交回复
热议问题