【发布时间】:2020-04-08 21:59:25
【问题描述】:
我对此很陌生,但遇到了 TypeError。我正在尝试用烧瓶模拟一个基本的网页。我已经设法将 HTML 请求从 HTML 文本框发送到我的程序。我正在尝试在另一个页面的表格中显示响应。
这是我的输入页面:
<!DOCTYPE html>
<html>
<body>
<form action = "/Attendance" method = "POST">
<p>Enter Employee Code:</p>
<p><input type = "text" name = "employee_code" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
输入进入这个程序:
import pyodbc
from flask import Flask, request, 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():
if request.method == 'POST':
req = request.form['employee_code']
conn = pyodbc.connect(
r'Driver={Microsoft Access Driver (*.mdb,
*.accdb)};DBQ=E:\xampp\htdocs\S10\SmartOffice.mdb;')
cursor = conn.cursor()
cursor.execute('select * from Employees where EmployeeCode =?', req)
for i in cursor.fetchall():
employee_id = str(i[0])
cursor.execute('select * from AttendanceLogs where EmployeeId=?', employee_id)
columns = [column[0] for column in cursor.description]
results = [columns] + [row for row in cursor.fetchall()]
for result in results:
return result
return render_template('Database_file.html', data=result)
if __name__ == '__main__':
app.run(debug=True)
我希望输出进入此处以表格形式显示:
<!DOCTYPE html>
<html>
<head>
<title>Attendance Table</title>
</head>
<body>
<table border = 1>
{% for key, value in data() %}
<tr>
<th> {{ key }} </th>
<td> {{ value }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>
但我得到了错误:
" {rv.class.name}.".format(rv=rv)
TypeError:视图函数未返回有效响应。返回类型必须是字符串、字典、元组、响应实例或 WSGI 可调用,但它是一个列表。
【问题讨论】: