@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')
我想删除我的数据库中的行给定id。例:
127.0.0.1:5002/delete/1
我得到的错误是:
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 -
看起来你在字符串之前和之前(id,)错过了cur.execute
行中的逗号。尝试使用以下内容
cur.execute('Delete from query_database where id == ?', (id,))
使用Django,要删除服务器内的数据库,删除模型,然后运行migrate和makemigrations。要删除记录,请通过表单和发布请求。希望它会有所帮助.....