Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Jinja2:将嵌套数组/字典动态复制到HTML表行中_Python_Flask_Jinja2 - Fatal编程技术网

Python Jinja2:将嵌套数组/字典动态复制到HTML表行中

Python Jinja2:将嵌套数组/字典动态复制到HTML表行中,python,flask,jinja2,Python,Flask,Jinja2,我一直在为我正在处理的应用程序动态创建一个事件表。我正在尝试使用Jinja2模板逻辑动态填充行。我使用flask进行路由,使用pure.css进行基本的css工作 我的数据组织如下: event_data{ device_name:[ {'summary':"", ... 'severity'}, {'summary':"", ... 'severity'}, .

我一直在为我正在处理的应用程序动态创建一个事件表。我正在尝试使用Jinja2模板逻辑动态填充行。我使用flask进行路由,使用pure.css进行基本的css工作

我的数据组织如下:

event_data{ device_name:[ {'summary':"", ... 'severity'},
                          {'summary':"", ... 'severity'},
                           .
                           .
                           .   ]
            device_name:[ ... ] }
我的模板代码:

    <div style="overflow:auto; height:150px; width:auto; border:1px solid; margin:20px;">
        <table class="pure-table">
            <thead>
                <tr>
                    <th>Name</th>
                    <th style="width:30%;">Summary</th>
                    <th>Last Seen</th>
                    <th>First Seen</th>
                    <th>Device Priority</th>
                    <th>Event Class</th>
                    <th>Production State</th>
                    <th>Severity</th>
                </tr>
            </thead>
            <tbody>
                {% for device in event_data %}
                    {% for event in event_data[device]%}
                        <tr>
                            <td>hello</td>
                            <td>{{ event['summary'] }}</td>
                            <td>{{ event['lastTime'] }}</td>
                            <td>{{ event['firstTime'] }}</td>
                            <td>{{ event['DevicePriority'] }}</td>
                            <td>{{ event['eventClass'] }}</td>
                            <td>{{ event['prodState'] }}</td>
                            <td>{{ event['severity'] }}</td>
                        </tr>
                    {%endfor%}
                {% endfor %}
            </tbody>
       </table>
    </div>

我测试了等效的python循环,它完美地打印了信息。当我像这样运行它时,它甚至不会进入内部循环,因此它不会使任何新行超过标题行。欢迎任何意见或建议

将某些内容转储到JSON会生成一个字符串。你不需要字符串,你需要的是你开始使用的dict。您没有做任何需要JSON的事情。只需传递dict而不使用
json.dumps

return render_template('app_page.html', event_data=json.dumps(event_data), device_names=devices)