使用Python将数据从PostgreSQL数据库传递到HTML
我目前正在尝试使用Python将数据从数据库(PostgreSQL)传递到HTML文件中使用Python将数据从PostgreSQL数据库传递到HTML,html,python-3.x,postgresql,Html,Python 3.x,Postgresql,我目前正在尝试使用Python将数据从数据库(PostgreSQL)传递到HTML文件中 import pandas as pd import psycopg2 from sqlalchemy import create_engine df = pd.read_sql('select * from "DATABASE".table_name Limit 100', con = engine ) HTML文件的一个片段: people = """ <!doctype html>
import pandas as pd
import psycopg2
from sqlalchemy import create_engine
df = pd.read_sql('select * from "DATABASE".table_name Limit 100', con = engine )
HTML文件的一个片段:
people = """
<!doctype html>
<html lang="en">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center">
<h1>PERSON</h1>
</div>
</div>
...
</html>
"""
这显然不起作用,我遇到了如何最好地继续下去的难题
因此,基本上需要为DB中的人员列表生成一堆HTML文件,并在HTML文件中的人员占位符中插入一个名称。这个名字来自数据库
关于你的任何建议/知识都可能是这个问题的开始,请让我知道。这是一个相当广泛的问题,因此你没有得到你想要的答案并不奇怪。“你看过类似的东西吗?”尼科格里芬。是的,我知道,以前从没做过这样的事。实际上,只是尝试使用python将数据放入html文件中
#we want HTML files that have the name of people from the DB attached to the HTML file
for i,rows in df.iterrows():
var1 = df.loc[i]['col1']
fileName = (f"people{name}.html")
people = open(fileName,"w")
#now place name of person inside HTML file, at PERSON with a name from the DB
for line in logData:
people.write(line.replace("PERSON", var1))
people.close()