Python / sqlite3将行插入数据库

时间:2018-08-04 18:35:04

标签: python-3.x sqlite sql-insert

我正在尝试使用下面的代码(一些版本)在数据库中添加一行,但是不断出现错误,表明我将太多的位置参数传递给execute()函数。这里的任何方向都很好。

代码:

username = request.form['username']
   #hash the password
password = generate_password_hash(request.form['password'])


#Execute sql to add value into db
# Add to database by creating a row with :username, :password (hash)
db.execute("INSERT INTO users VALUES(?,?)", (username, password))

OR

db.execute("INSERT INTO users(username, password) VALUES(?,?)", (username, password))

OR

db.execute("INSERT  INTO users (username, hash) VALUES (:username, :hash)", username, password)

错误

"execute() takes 2 positional arguments but 3 were given"

0 个答案:

没有答案
相关问题