Download Code/flask_migrate/app.py from zxy0307/Python_05_Flask: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/zxy0307/Python_05_Flask/resolve/main/Code/flask_migrate/app.py
- Command line
-
hf download hf://zxy0307/Python_05_Flask/Code/flask_migrate/app.py
-
curl -L -o app.py https://huggingface.co/zxy0307/Python_05_Flask/resolve/main/Code/flask_migrate/app.py
765 Bytes
| from flask import Flask | |
| from flask_sqlalchemy import SQLAlchemy | |
| app = Flask(__name__) | |
| # 数据库的变量 | |
| HOST = '127.0.0.1' | |
| PORT = 3306 | |
| DATA_BASE = 'flask_db' | |
| USER = 'root' | |
| PWD = 'zxydsg123' | |
| DB_URI = f'mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DATA_BASE}' | |
| app.config['SQLALCHEMY_DATABASE_URI'] = DB_URI | |
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
| db = SQLAlchemy(app) | |
| # 创建模型类 | |
| class User(db.Model): | |
| __tablename__ = 't_user' | |
| id = db.Column(db.Integer,primary_key = True,autoincrement = True) | |
| name = db.Column(db.String(32)) | |
| age = db.Column(db.Integer) | |
| city = db.Column(db.String(32)) | |
| def __repr__(self): | |
| return f'<User id={self.id} name={self.name}>' | |
| from flask_migrate import Migrate | |
| Migrate(app, db) |