ignore *.ini 규칙 추가

app.py 파일 추가
This commit is contained in:
김민구
2024-01-05 12:36:53 +09:00
parent 3db6a5779f
commit 4daef569c5
2 changed files with 54 additions and 1 deletions

2
.gitignore vendored
View File

@@ -164,3 +164,5 @@ cython_debug/
.DS_Store .DS_Store
.AppleDouble .AppleDouble
.LSOverride .LSOverride
*.ini

51
app.py Normal file
View File

@@ -0,0 +1,51 @@
# -*- coding:utf-8 -*-
import configparser
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return result
if __name__ == '__main__':
app.run()
import pymysql
config = configparser.ConfigParser()
# DB 연결 설정 정보 세팅 ( db_config.ini에 정의 )
config.read(os.getcwd() + os.sep + 'db_config.ini', encoding='utf-8')
conn = pymysql.connect(
host = config.get('DB_CONFIG', 'HOST'),
port = int(config['DB_CONFIG']['PORT']),
user= config['DB_CONFIG']['USER'],
passwd= config.get('DB_CONFIG', 'PASSWD'),
db= config['DB_CONFIG']['DBNAME'],
charset="utf8")
# Tuple
cur = conn.cursor()
# DictCursor
cur = conn.cursor(pymysql.cursors.DictCursor)
sql = f"""SELECT * FROM authority
"""
# sql = f"""SELECT * FROM product
# """
#cur.execute("set name utf8")
cur.execute(sql)
# 데이터 접근
result = cur.fetchall()
# 연결 종료
conn.close()
print(result)