목록Python/Flask (21)
군침이 싹 도는 코딩
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() # --..
def put(self, recipe_id) : # ----------- 함수를 만든다 data = request.get_json() # ----------- 포스트맨에서 제이슨을 받아온다 try : connection = get_connection() # ----------- 커넥션을 만든다 query = '''update recipe set name = %s , description = %s , num_of_servings = %s , cook_time = %s , directions = %s where id = %s; ''' # ---------- 업데이트를 위한 쿼리문을 만들고 값을 변수로 치환 record = ( data['name'], data['description'], data['num_o..
import mysql.connector def get_connection() : connection = mysql.connector.connect( host = '호스트이름', database = 'DB이름', user = 'USER명', password = '비밀번호', ) return connection try : # 데이터 select # 1. DB에 연결 connection = get_connection() # 2. 쿼리문 만들기 query = '''select * from mysql_table;''' # 3. 커서를 가져온다. # select의 경우 dictionary = True로 설정한다. cursor = connection.cursor(dictionary = True) # 4. 쿼리문을 ..
import mysql.connector def get_connection() : connection = mysql.connector.connect( host = '호스트이름', database = 'DB이름', user = 'USER명', password = '비밀번호', ) return connection try : # 데이터 insert # 1. DB에 연결 connection = get_connection() # 2. 쿼리문 만들기 query = '''insert into mysql_table (col1, col2, ...) values (value1, value2, ...);''' # 3. 커서를 가져온다. cursor = connection.cursor() # 4. 쿼리문을 커서를 이용해서 실..

$conda create -n 가상환경이름 python=3.8 openssl numpy scipy matplotlib ipython scikit-learn pandas pillow jupyter seaborn # 먼저 플라스크를 사용하기 위한 가상환경을 세팅해준다 # conda activate 가상환경이름 타이핑해서 만든 가상환경으로 이동 후 플라스크를 설치한다 pip install flask pip install flask-restful # 플라스크와 플라스크레스풀 라이브러리의 설치 명령어