[Python] Python Flask-RESTful method delete error - "message": "The method is not allowed for...

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    What could be the problem?

    I have a function that deletes a record from the database by id. Function separately from api works.

    def delete_student(student_id: int):
    del_student = db.session.query(Student).filter_by(id=student_id).one()
    db.session.delete(del_student)
    return db.session.commit()



    But when i use this function via api i get error: {"response": {"message": "The method is not allowed for the requested URL."}}

    class AddDeleteStudent(Resource):
    def delete(self, user_id):
    return delete_student(user_id)

    api.add_resource(AddDeleteStudent, '/api/v1/students/<int:user_id>')

    Continue reading...

Compartilhe esta Página