我无法将一些简单的数据从 html 页面放入 MySQL 数据库
我收到的错误是
werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: KeyError: 'matchID'
这是我用来将其推送到 MySQL 数据库的 python 代码
import mysql.connector as conn
from flask import (
render_template,
Flask,
jsonify,
request,
abort as ab
)
app = Flask(__name__)
def conn_db():
return conn.connect(user='***********',
password='***********',
host='***********',
database='**********'
)
@app.route('/')
def index():
return render_template('scores.html')
@app.route('/addScore', methods=['POST'])
def add_score():
cnx = conn_db()
cursor = cnx.cursor()
MatchID = request.form['matchID']
Home_Score = request.form['homeScore']
Away_Score = request.form['awayScore']
print("Updating score")
if not request.json:
ab(400)
cursor.execute("INSERT INTO scores (Match_ID, Home_Score, Away_Score) VALUES (%s,%s,%s,%s)",
(MatchID, Home_Score, Away_Score))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
紫衣仙女
相关分类