首页 > 解决方案 > 无法将 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>

但是当我运行这些代码时,框架正在显示,但它的内容没有可视化我试图找出哪个是错误的,但很难找到解决方案

有什么代码错了吗?或每个代码的目录是错误的?

我希望有人能给我建议

提前致谢

标签: pythonhtml

解决方案


推荐阅读