8

How to use Delete method in python flask. My code segment has some issues and it shows Method Not Allowed while loading the url http://localhost:8082/api/users/remove_group/5.

@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
9
  • Is your html pointing at the right method? stackoverflow.com/questions/24088054/… or stackoverflow.com/questions/12179593/…. BTW why the Java tag? Commented Feb 6, 2017 at 12:04
  • Thanks for your effort @doctorlove, But the link says about get and post methods only.What about Delete method...? Commented Feb 6, 2017 at 12:18
  • True, however the error was the same Commented Feb 6, 2017 at 12:19
  • Tried methods=['GET', 'DELETE'] ? Commented Feb 6, 2017 at 12:19
  • Already tried with ['GET', 'DELETE'],Thats worked successfully.but when iam using only the Delete Method then it shows Method not allowed Commented Feb 6, 2017 at 12:23

1 Answer 1

-1

HTML suports only GET/POST requests in forms, isn't it? Thus, you might try to get access to your removeGroup method with POST request that is not allowed in @app.route.

Please, see also: Should PUT and DELETE be used in forms?

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer is inrelevant to the question. How can your server handle DELETE requests. It is flask, serverside code. The request doesn't have to be comming from a form.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.