当他们输入用户名和密码时,我正在尝试将用户添加到数据库中。但是,数据库根本没有更新,数据库中的所有信息都保持不变。我已经测试了代码,它确实在运行,但是mysql.connect().commit()没有将代码提交到数据库。
我的烧瓶文件:from flask import Flask, jsonify, render_template, request, Response, json, redirect, url_for
from flaskext.mysql import MySQL
import re
from MyFunction import *
from get_tv_name import *
mysql = MySQL()
app = Flask(__name__, static_folder="", static_url_path='')
app.config['SECRET_KEY'] = 'F34TF$($e34D';
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = ""
app.config['MYSQL_DATABASE_DB'] = 'accounts'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/register.html/', methods=['GET', 'POST'])
def register():
error = None
if request.method == 'POST':
cursor = mysql.connect().cursor()
cursor.execute("SELECT * from _accounts where Username='" + request.form['username'] + "' and Password='" + request.form['password'] + "'")
data = cursor.fetchone()
if data == None:
cursor.execute("INSERT INTO _accounts VALUES (null, '" + request.form['username'] + "', '" + request.form['password'] + "')")
mysql.connect().commit
redirect(url_for('index'))
else:
error = "it is complete"
return render_template('/register.html/', error=error)
if __name__ == '__main__':
app.run(port=8080, debug=True)
我的html:
First Name
Last Name
Username
Password
Create account