首页 > 解决方案 > WHy can't i delete from my database on sqlite3?

问题描述

@app.route("/delete/<id>", methods=['POST'])
def remove(id):

    connection = sqlite3.connect('database.db')
    cur = connection.cursor()

    cur.execute('Delete from query_database where id == ?' (id,))
    cur.close()
    return ('status.HTTP_200_OK')

I want to delete lines off my database given the id. example:

127.0.0.1:5002/delete/1

The error i'm getting is:

File "api_calls.py", line 65, in remove
    cur.execute('Delete from query_database where id == ?' (id,))
TypeError: 'str' object is not callable
127.0.0.1 - - [03/Sep/2018 18:33:56] "POST /delete/1 HTTP/1.1" 500 -

标签: pythonsqlite

解决方案


看起来您在cur.execute字符串之后和 (id, ) 之前的行中缺少逗号。尝试使用以下

cur.execute('Delete from query_database where id == ?', (id,))

推荐阅读