python - 无法将 csv 数据导入到 HTML 中每个帧的表格(#tablib)
问题描述
我想在一个屏幕中导入两个表
所以首先,我将帧分为 3 帧(上、左、右)
左右框架应导入csv数据并填满表格。
Py 和 HTML 代码目录是
web_test\
└app.py
└test.csv
templates\
└index.html
└__init__.py
└dataset1.html
└dataset2.html
└frame1.html
static\
css\
└style.css
我试图像这样生成每个 html & py 的代码
应用程序.py
from flask import Flask, render_template
import tablib
import os
app = Flask(__name__)
dataset1 = tablib.Dataset()
with open(os.path.join(os.path.dirname(__file__), 'test.csv')) as f:
dataset1.csv = f.read()
dataset2 = tablib.Dataset()
with open(os.path.join(os.path.dirname(__file__), 'test.csv')) as f:
dataset2.csv = f.read()
@app.route("/")
def index():
return render_template('index.html')
@app.route("/dataset1")
def dataset1():
data1= dataset1.html
# return dataset.html
return render_template('dataset1.html', data=data1)
@app.route("/dataset2")
def dataset2():
data2 = dataset2.html
# return dataset.html
return render_template('dataset2.html', data=data2)
if __name__ == "__main__":
app.run()
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<Frameset rows = "17%, 1*" border="0">
<frame src ="../frame1.html" name="frame1" scrolling ="no", marginwidth="0" marginheight="0">
<Frameset cols="30%,*">
<Frame src = "../dataset1.html" name="dataset1" scrolling="no" marginwidth="0" marginheight="0">
<frame src ="../dataset2.html" name="dataset2" scrolling ="no", marginwidth="0" marginheight="0">
</Frameset>
</Frameset>
<BODY>
</BODY>
</html>
数据集1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dataset1</title>
</head>
<body>
<h1>This dataset1</h1>
<div class = "table">
{%block body %}
{{data|safe}}
{% endblock%}
</div>
</body>
</html>
数据集2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dataset2</title>
</head>
<body>
<h1>This dataset2</h1>
<div class = "table">
{%block body %}
{{data|safe}}
{% endblock%}
</div>
</body>
</html>
框架1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
Test
</body>
</html>
但是当我运行这些代码时,框架正在显示,但它的内容没有可视化我试图找出哪个是错误的,但很难找到解决方案
有什么代码错了吗?或每个代码的目录是错误的?
我希望有人能给我建议
提前致谢
解决方案
推荐阅读
- django - 当发布对象包含空字符串时,使用来自 react 到 django rest 框架的 axios post 得到 400(错误请求)
- symfony - 捆绑控制器的依赖注入
- python - cv2.VideoWriter:请求一个元组作为 Size 参数,然后拒绝它
- spring-boot - Springboot 405 方法在 Pivotal Web Services/Cloud Foundry 中不允许,但在本地 docker 中工作
- django - 监视和检测 Excel 文件中的更改并刷新网页的位置
- hadoop - Hadoop:如何正确停用集群上的节点?
- python - 如何提供标量作为 pyplot 绘图函数的数据点坐标?
- ansible - ansible uri 模块失败(lineno\\": 0\\n}' 不是 u'object 类型)(输入有效负载验证失败)
- namespaces - CertificateWebRequestHandlerModifierOptions 位于哪个命名空间中?
- c# - EF Linq - 动态 Lambda 表达式树