【问题标题】:Bring data from a SQL Server table to flask Python and then show in html将数据从 SQL Server 表带到烧瓶 Python,然后以 html 显示
【发布时间】:2022-11-13 18:00:43
【问题描述】:

我正在尝试在后端使用烧瓶和 python 制作一个 html 网站。我想集成 Microsoft SQL Server 以在网站上显示我的表中的数据。

我的问题是我已经使用以下代码成功地从数据库表中获取数据:

def database():
    conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
                      'Server=RIZWAN-LAPTOP;'
                      'Database=MultiCarePharmacy;'
                      'Trusted_Connection=yes;')

    cursor = conn.cursor()
    data = pd.read_sql("SELECT ID FROM Employee", conn) #pd is panda library
    conn.commit()
    return data

这个data 包含我使用以下代码发送到 html 的整个表:

def editEmployee():
    
    (to_send)=str(database())
    return render_template("editEmployee.html",to_send=to_send)

这里to_send=data 所以问题是表格在控制台中完美显示,但在 html 下拉框中变形。 html select box

在控制台上,表格显示为: console output

【问题讨论】:

    标签: html sql flask ssms


    【解决方案1】:

    仅供参考我不使用熊猫

    使用 Flask 字典尝试 HTML Jinja2 模板

    【讨论】:

      猜你喜欢
      • 2017-02-10
      • 1970-01-01
      • 2019-03-09
      • 2019-02-24
      • 2022-10-23
      • 2020-09-26
      • 2017-09-30
      • 2021-10-04
      相关资源
      最近更新 更多