python - 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 -
解决方案
看起来您在cur.execute
字符串之后和 (id, ) 之前的行中缺少逗号。尝试使用以下
cur.execute('Delete from query_database where id == ?', (id,))
推荐阅读
- r - 从 lmer 中找到 Y=0 的 X ± SD
- android - 出现错误:package androidx.viewbinding 不存在错误
- haskell - haskell中的部分函数应用和折叠
- python - 如何在matplotlib / seaborn散点图中标记图外的点
- python - 如何检查 discord.py 中某条消息的反应计数?
- angular - 如何测试 lasValueFrom 响应并且没有收到消息:“序列中没有元素”名称:“EmptyError”
- r - 如何从 R Shiny 的选项菜单中拆分选定的列?
- reactjs - 如何避免 componentDidMount 中的持续 api 调用
- java - 为什么 Gradle 在使用 exclude 时不排除传递依赖?
- angular - Angular:如何在响应中获取内部对象数据?