网站建设高清图,如何从零开始学做电商?,建设工程安全管理网站,wordpress在线储存在django前端页面上展示的数据#xff0c;还是使用django模板自带的语法
方式1 不推荐使用 直接使用 【df.to_html(indexFalse)】 使用to_html他会生成一个最基本的表格没有任何的样式#xff0c;一点都不好看#xff0c;如果有需要的话可以自行修改表格的样式#xff0c;…在django前端页面上展示的数据还是使用django模板自带的语法
方式1 不推荐使用 直接使用 【df.to_html(indexFalse)】 使用to_html他会生成一个最基本的表格没有任何的样式一点都不好看如果有需要的话可以自行修改表格的样式但博主觉得这样的方式太麻烦 后端
df pd.DataFrame({Name: [John, Alice, Smith],Age: [30, 25, 35],City: [New York, London, Paris]})# 将DataFrame转换为HTML字符串
table_html df.to_html(indexFalse)# 将表格数据和其他数据打包成上下文对象
content {table_html: table_html}
return render(request, 自己的前端网页, content)前端
!DOCTYPE html
html
head
/head
bodytable{{ table_html | safe }}/table!-- 其他页面内容 --
/body
/html 效果 方式2 推荐使用 将df转为字典放到特定的表格下 这个表格是博主已经写好table有一定的样式了这个方式就是将每一行数据给放到表格里面相当于只是传递了数值。 下面的django模板语法能够动态的更新标题行和数据数据表格有变动不需要修改前端模板 后端
df pd.DataFrame({Name: [John, Alice, Smith],Age: [30, 25, 35],City: [New York, London, Paris]})
table_data df.to_dict(records)
table_headers df.columns.tolist()
content {table_headers:table_headers,table_data: table_data
}
return render(request, 自己的前端网页, content)前端
!DOCTYPE html
html
head
/head
bodydiv classtable-responsivediv idexample_wrapper classdataTables_wrappertable idexample classdisplay table dataTable rolegridaria-describedbyexample_infotheadtr{% for header in table_headers %}th{{ header }}/th{% endfor %}/tr/theadtbody{% for row in table_data %}tr{% for value in row.values %}td{{ value }}/td{% endfor %}/tr{% endfor %}/tbody/table/div/div!-- 其他页面内容 --
/body
/html 效果