我正在尝试创建一个烧瓶应用程序,其中我在网页上有一个文本框。当按下提交时,它会搜索在 postgres 数据库表的文本框中输入的内容。
我收到以下错误:
错误请求浏览器(或代理)发送了此服务器无法理解的请求。”
我的代码如下:
应用程序.py
from flask import Flask, render_template, request
from sqlalchemy import create_engine
app = Flask(__name__)
app.config['DEBUG']
db_string = "postgres://xx:xx@xx:5432/xx"
db = create_engine(db_string)
@app.route('/', methods=['GET', 'POST'])
def homepage():
jn = request.form['jobnumber']
result_set = db.execute("SELECT cost FROM public.options where optionno = (f'%{jn}%')").fetchall()
return render_template('main.html', test=result_set, jn=jn)
if __name__ == "__main__":
app.run(debug=True)
和我的html文件:
main.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>xxx</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
<p>xxx</p>
<form method="POST">
<input name="jobnumber" type="submit" placeholder="jn">
</form>
<table>
<td>
{{test}}
</td>
</table>
</body>
</html>
我敢肯定,它会很容易解决,但我正在努力,所以任何帮助都将不胜感激。