Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用Delete方法_Python_Html_Flask Sqlalchemy - Fatal编程技术网

如何在python中使用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

如何在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 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