我的结果被截断为一行。我如何让它打印所有内容?
My results are truncating into a single row. How do I get it to print everything?
这是我的代码:
'
导入pyodbc
将 pandas 导入为 pd
从烧瓶导入烧瓶,请求,render_template
app = Flask(__name__)
@app.route('/')
def attendance_fetch():
return render_template('Attendance_fetch.html')
@app.route('/Attendance', methods=['GET', 'POST'])
def database_file():
df = 0
if request.method == 'POST':
employee = request.form['employee_code']
conn = pyodbc.connect(
r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=file_location;')
cursor = conn.cursor()
cursor.execute('select * from Employees where EmployeeCode =?', employee)
for i in cursor.fetchall():
employee_id = str(i[0])
cursor.execute('select EmployeeID, AttendanceDate, InTime, OutTime, TotalDurationinHHMM'
' from AttendanceLogs where EmployeeId=?', employee_id)
columns = [column[0] for column in cursor.description]
print(columns)
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
for result in results:
final = [result]
df = pd.DataFrame(final)
return render_template('Testrun2.html', tables=[df.to_html(classes='data')],
titles=df.columns.values)
cursor.close()
conn.close()
if __name__ == '__main__':
app.run(debug=True)
'
然后我写了一个 html 文件来捕获它:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Attendance Table</title>
</head>
<body>
{% for table in tables %}
{{titles[loop.index]}}
{{ table|safe }}
{% endfor %}
</body>
</html>
But the result is just a singular truncated column:
我想打印每一行结果。提前致谢。
问题出在:
for result in results:
final = [result]
df = pd.DataFrame(final)
您在每个循环中覆盖了您的 df,包含一个结果。将 df 放在循环外并尝试它是否有效。
这是我的代码: '
导入pyodbc 将 pandas 导入为 pd 从烧瓶导入烧瓶,请求,render_template
app = Flask(__name__)
@app.route('/')
def attendance_fetch():
return render_template('Attendance_fetch.html')
@app.route('/Attendance', methods=['GET', 'POST'])
def database_file():
df = 0
if request.method == 'POST':
employee = request.form['employee_code']
conn = pyodbc.connect(
r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=file_location;')
cursor = conn.cursor()
cursor.execute('select * from Employees where EmployeeCode =?', employee)
for i in cursor.fetchall():
employee_id = str(i[0])
cursor.execute('select EmployeeID, AttendanceDate, InTime, OutTime, TotalDurationinHHMM'
' from AttendanceLogs where EmployeeId=?', employee_id)
columns = [column[0] for column in cursor.description]
print(columns)
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
for result in results:
final = [result]
df = pd.DataFrame(final)
return render_template('Testrun2.html', tables=[df.to_html(classes='data')],
titles=df.columns.values)
cursor.close()
conn.close()
if __name__ == '__main__':
app.run(debug=True)
'
然后我写了一个 html 文件来捕获它:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Attendance Table</title>
</head>
<body>
{% for table in tables %}
{{titles[loop.index]}}
{{ table|safe }}
{% endfor %}
</body>
</html>
But the result is just a singular truncated column: 我想打印每一行结果。提前致谢。
问题出在:
for result in results:
final = [result]
df = pd.DataFrame(final)
您在每个循环中覆盖了您的 df,包含一个结果。将 df 放在循环外并尝试它是否有效。