33"""
44
55from flask import Flask
6+ from flask_sqlalchemy import SQLAlchemy
7+ from sqlalchemy .sql import text
8+
9+ DB = SQLAlchemy ()
10+ SQLALCHEMY_DATABASE_URI = \
11+ ("mysql+pymysql://{USER}:{PASSWORD}@{ADDR}:{PORT}/{NAME}?charset=utf8" )
12+
13+ class Userinfo (DB .Model ):
14+ """ Userinfo model """
15+ __tablename__ = "userinfo"
16+ __table_args__ = {'mysql_collate' : 'utf8_general_ci' }
17+ id = DB .Column ("id" , DB .Integer , primary_key = True )
18+ name = DB .Column ("name" , DB .String (250 ), nullable = False )
19+ tel = DB .Column ("tel" , DB .String (20 ), nullable = False )
20+ created = DB .Column (DB .TIMESTAMP , server_default = text ("CURRENT_TIMESTAMP" ), nullable = False )
21+
22+ def __init__ (self , name , tel ):
23+ self .name = name
24+ self .tel = tel
625
726def create_app () -> (Flask ):
827 """ create_app() 함수를 호출해 앱을 초기화 """
28+
29+ """ app config part """
30+ # 나중에 config는 다 빼야 할 것 같다.
931 app = Flask (__name__ )
1032 app .app_context ().push ()
33+ app .config ['SQLALCHEMY_DATABASE_URI' ] = SQLALCHEMY_DATABASE_URI .format (
34+ USER = "root" ,
35+ PASSWORD = "1234" ,
36+ ADDR = "127.0.0.1" ,
37+ PORT = 3306 ,
38+ NAME = "board"
39+ )
40+ app .config ['SQLALCHEMY_ECHO' ] = True
41+ app .config ['DEBUG' ] = True
42+ DB .init_app (app )
1143
44+ """ route part """
45+ # 나중에 route는 다 빼야 할 것 같다.
1246 @app .route ("/" )
1347 def index ():
1448 """ / url index """
1549 return "<h1>Hello World ! <br> This is index page</h1>"
1650
51+ """ return part """
1752 return app
0 commit comments