如何在python flask中使用Delete方法

问题描述 投票:1回答:1

如何在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
python html flask-sqlalchemy
1个回答
1
投票

HTML只支持表单中的GET / POST请求,不是吗?因此,您可能尝试使用removeGroup中不允许的POST请求访问您的@app.route方法。

请参阅:Should PUT and DELETE be used in forms?

© www.soinside.com 2019 - 2024. All rights reserved.