Notice
Recent Posts
Recent Comments
Link
뭐야 왜 an 돼
Python MySQL Connector Delete 본문
포스트맨을 실행시켜 Delte로 설정하고 URL을 입력해줍시다.

Visual Studio Code에서 아래처럼 코드를 작성해주세요
+ app.py에 경로와 리소스(API코드)를 연결하는 코드도 작성해줍시다.
>>> api.add_resource(RecipeResource, '/recipes/<int:recipe_id>')
class RecipeResource(Resource) :
def delete(self, recipe_id) :
try :
connection = get_connection()
query = ''' delete from recipe
where id = %s; '''
record = (recipe_id, )
cursor = connection.cursor()
cursor.execute(query, record)
connection.commit()
cursor.close()
connection.close()
except Error as e :
print(e)
cursor.close()
connection.close()
return {"result" : "fail", "error" : str(e)}, 500
return {"result" : "success"}, 200
데이터가 업데이트 되었는지 MySQL Workbench에서 확인해주세요
'RESTful API' 카테고리의 다른 글
| API, serverless 와 깃허브 Actions로 AWS 자동 배포 설정 하기 (0) | 2024.05.24 |
|---|---|
| Python MySQL Connector update (0) | 2024.05.21 |
| RESTful API로 레시피 목록 가져오기: Python과 Flask 활용(Selecet) (0) | 2024.05.21 |
| Python을 사용한 MySQL 데이터베이스 연결 설정 (0) | 2024.05.21 |
| Python MySQL Connector insert 하는 방법 (Flask,Post man) (0) | 2024.05.21 |