【问题标题】:Display datraframe into django template将数据框显示到 django 模板中
【发布时间】:2018-03-07 21:10:25
【问题描述】:

我目前正在使用Django 开发一个统计门户网站,我正在尝试在我的模板中显示Dataframe 并使用下一个代码:

查看.py:

def tabla(request):
    engine = create_engine('postgresql://postgres:alphabeta@localhost:5432/escaladas')
    t='escalado 08/2017'
    sqltable = ps.read_sql_table(t,engine)
    sqltablehead = sqltable.head(n=10)
    table = sqltablehead.to_html(classes='table',index=False,escape=False)
    return render(request,'escalamiento.html',{'table':table})

我尝试在模板上显示带有for 的表格,但没有显示任何内容并写了{{table}},但给了我这个https://ibb.co/bVpWw5

有什么想法吗?

【问题讨论】:

    标签: python django pandas templates bootstrap-4


    【解决方案1】:

    改用{{table|safe}},这样HTML 就不会得到escaped。

    【讨论】:

      猜你喜欢
      • 2016-12-24
      • 2021-10-08
      • 2012-03-18
      • 2014-11-12
      • 2013-02-17
      • 2011-07-10
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      相关资源
      最近更新 更多