Files
student_manage_system/students/databases.py
T

26 lines
494 B
Python
Raw Normal View History

# databases链接数据库
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker,declarative_base
db_url = "mysql+pymysql://root:420821@localhost:3306/student_manage_system?charset=utf8mb4"
engine1 = create_engine(db_url)
Base = declarative_base()
Session = sessionmaker(bind=engine1
,autoflush=False
,autocommit=False)
def get_db():
db = Session()
try:
yield db
finally:
db.close()