我正在尝试使用python / flask将新用户添加到现有的postgresql表中 输入似乎运行良好,但是写入数据库时出现错误。我尝试了所有可能的括号排列方式,但没有成功
在登录名中输入数据时,出现以下错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near "'user'"
LINE 1: INSERT INTO 'user' (username, password) VALUES ('joe', 'abcd...
^
[SQL: "INSERT INTO 'user' (username, password) VALUES ('joe', 'abcd')"]
这是python代码:
@app.route("/register", methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
reg = db.execute("INSERT INTO user (username, password) VALUES(':uname', ':pword')",
{"uname": username, "pword": password})
print(reg)
db.commit()
return render_template('login.html')
return render_template('register.html')