用Python将microsoftsql数据打印到webpag上

2024-04-25 23:22:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一些帮助来弄清楚为什么我的结果只打印出表中的最后一行数据。你知道吗

from flask import Flask, render_template, redirect, request

import pyodbc

#server = 'EVERETT-PC\SQLEXPRESS'
#db = 'AdventureWorks2008R2'

con = pyodbc.connect('Trusted_Connection=yes', driver = '{SQL Server}',server = 'EVERETT-PC\SQLEXPRESS' , database = 'iNcentDev')

cur = con.cursor()
cur.execute("SELECT * FROM app.Currency")
s = "<table style= 'border:1px solid red'>"
for rows in cur:
    s = s + "<tr>"
for x in rows:
    s = s + "<td>" + str(x) + "</td>"
s = s + "</tr>"

con.close

app=Flask(__name__)
@app.route('/')
@app.route('/home')
def home():
  return "<html><body>" + s + "</body></html>"

if __name__=="__main__":
    app.run(debug=True)

The data I would like to print.

my results


Tags: inimportappflaskforservercontr