【发布时间】:2017-02-06 11:41:07
【问题描述】:
如何在 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
【问题讨论】:
-
您的 html 是否指向正确的方法? stackoverflow.com/questions/24088054/… 或 stackoverflow.com/questions/12179593/…。顺便说一句,为什么要使用 Java 标记?
-
感谢@doctorlove 的努力,但该链接仅表示 get 和 post 方法。Delete 方法怎么样...?
-
是的,但是错误是一样的
-
试过
methods=['GET', 'DELETE']? -
已经用 ['GET', 'DELETE'] 试过了,这很成功。但是当我只使用删除方法时,它显示方法不允许
标签: python html flask-sqlalchemy