如何在python中使用Delete方法
如何在PythonFlask中使用Delete方法。我的代码段有一些问题,它显示了加载url时不允许使用Delete方法如何在python中使用Delete方法,python,html,flask-sqlalchemy,Python,Html,Flask Sqlalchemy,如何在PythonFlask中使用Delete方法。我的代码段有一些问题,它显示了加载url时不允许使用Delete方法 @app.route('/api/users/remove_group/',methods=['DELETE']) def removeGroup(组ID): 尝试: 打印“其工作组--删除组” 如果userGroup.query.filter\u by(group\u id=groupId).first()不是None: userGroup.query.filter\u b
@app.route('/api/users/remove_group/',methods=['DELETE'])
def removeGroup(组ID):
尝试:
打印“其工作组--删除组”
如果userGroup.query.filter\u by(group\u id=groupId).first()不是None:
userGroup.query.filter\u by(group\u id=groupId).delete()
message='Group已成功删除\n'
其他:
打印“未找到组”
message='Group未找到\n'
除了HTTPException作为错误:
返回错误(os.version)
回信
HTML支持只在表单中获取/发布请求,不是吗?因此,您可以尝试使用POST
请求访问@app.route
中不允许的removeGroup
方法
另请参见:
您的html是否指向正确的方法?或顺便说一句,为什么要使用Java标记?感谢@doctorlove的努力,但是链接中只提到了get和post方法。那么Delete方法呢…?是的,但是错误是sameTried
方法=['get',Delete']
?已经用['get',Delete']尝试过了,但是当我只使用Delete方法时,它表明方法不允许。你的答案与问题无关。您的服务器如何处理删除请求。这是flask,服务器端代码。请求不必来自表单。
@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