首页 > 解决方案 > 如何在 Datatable 中呈现图像链接

问题描述

我在烧瓶应用程序中有下表。第一列应该呈现一个完整的链接语句,例如:

<a href ="https://www.website.com/i=2xyz2g" target="_blank"> <img src="/static/assets/img/abc.jpg" width="100" height="100"></a>

数据来自查询: 表如下:

 |img                               |  Title   | 
 -----------------------------------------------
 |  the <a> script  above goes here | some text|

我想编写 javascript 来呈现图像/链接。

                    <table id="table_id" class="display compact" style="width:100%">
                        <thead>
                            <tr>
                                {% for col in img_list_cols %}
                                <th>{{col}}</th>
                                {% endfor %}
                            </tr>
                        </thead>
                        <tbody>
                            {% for row in img_list_rows %}
                            <tr>
                                {% for row_data in row %}
                                <td>{{row_data}}</td>
                                {% endfor %}
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>

标签: javascriptflaskdatatablejinja2

解决方案


您可以使用 Jinjasafe过滤器,例如。

<td>{{row_data|safe}}</td>

推荐阅读