如何在python Flask中使用Delete方法

Ren*_*h R 5 html python flask-sqlalchemy

如何在 python flask 中使用 Delete 方法。我的代码段有一些问题,它在加载 url http://localhost:8082/api/users/remove_group/5时显示 Method Not Allowed 。

@app.route('/api/users/remove_group/<int:groupId>',methods=['DELETE'])
def removeGroup(groupId):
try:
    print 'its working--Delete group'
    if userGroup.query.filter_by(group_id=groupId).first() is not None:
        userGroup.query.filter_by(group_id=groupId).delete()
        message='Group removed succesfully\n'
    else:
        print 'Group not found'
        message='Group not found\n'
except HTTPException as error:
    return error(os.version)
return message
Run Code Online (Sandbox Code Playgroud)

pch*_*pch 0

HTML 仅支持表单中的 GET/POST 请求,不是吗?因此,您可能会尝试removeGroup使用.POST@app.route

请参阅: 表单中应该使用 PUT 和 DELETE 吗?

  • 你的回答与问题无关。您的服务器如何处理 DELETE 请求。它是 Flask,服务器端代码。该请求不必来自表单。 (7认同)