下面实现一个插入表操作
from flask import Flask from flask_sqlalchemy import SQLAlchemy import config app = Flask(__name__) app.config.from_object=(config) db = SQLAlchemy(app) class article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer,primary_key=True,autoincrement=True) title = db.Column(db.String(100),nullable=False) content = db.Column(db.Text,nullable=False) db.create_all() @app.route('/') def index(): return 'Hello World!' if __name__ == '__main__': app.run(debug=True)
配置文件config.py:
SQLALCHEMY_DATABASE_URI ='mysql+pymysql://root:root@127.0.0.1:3306/db_demo2'
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231252.html原文链接:https://javaforall.net
