python3 Flask-SQLAlchemy的使用

dede.py

import pymysql
import config
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object(config)
db = SQLAlchemy(app)
db.create_all()


@app.route('/')
def index():
    return 'index'


if __name__ == '__main__':
    app.run(debug=True)

config.py

USERNAME = 'root'
PASSWORD = 'root'
HOST = '127.0.0.1'
PORT = 3306
DATABASE = 'demo_01'

SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(USERNAME, PASSWORD, HOST, PORT, DATABASE)
SQLALCHEMY_TRACK_MODIFICATIONS = False

你可能感兴趣的:(python3 Flask-SQLAlchemy的使用)