python - 是否可以将两个数据帧发送到我的 html(烧瓶)?
问题描述
所以我的 html 页面收到了一个 pandas 数据框。
return render_template('example.html', tables=[data_frame.to_html(classes='data')], titles=dataframe.columns.values)
我的html页面显示它:
{% for table in tables %}
{{titles[loop.index]}}
{{ table|safe }}
{% endfor %}
我想要做的是在我的 html 页面中显示两个单独的数据框。我怎样才能做到这一点?
例如:如果我有数据框 df1 和 df2,
在 html 页面中,我想在一些文本之后显示它们。
show df1
<h2> some text </h2>
show df2
解决方案
由于render_template
接受字典,您可以使用“table”和“title”键将名为 context 或其他任何内容的 Dict 对象传递给“render_template”函数。context.table
然后在您的 Jinja 中,您可以通过和访问这些密钥context.title
。
例子:
def my_function(request):
...
get your dataframe
...
context = {"tables":[data_frame.to_html(classes='data')],
"titles" : dataframe.columns.values,
}
return render_template('template.html', context=context)
推荐阅读
- angular - Typescript filter an array using filter()
- php - Move plugin modification outside of plugin files
- java - dispatchGesture 如何在没有取消手势的情况下添加更多手势?
- java - 使用 java 以编程方式从 Websphere 检索 .class 文件输出位置
- php - 再次在页面之间发送变量?
- angularjs - New route re-writes URL to default route, SignalR stops connecting
- spring - 如何在 Thymeleaf 中获取 lastIndex
- css - Angular4 mat-form-field textArea can not enable horizontal resize
- java - JLabel: Squish text if it doesn't fit
- javascript - 挑战:通过 AJAX 加载重力表单 - 将 PHP 解决方案更改为 Gutenberg 代码