Flask-sqlalchemy是關(guān)于flask一個針對數(shù)據(jù)庫管理的。文中我們采用一個關(guān)于員工顯示例子。
首先,我們創(chuàng)建SQLALCHEMY對像db。
1 from flask import Flask, render_template,request 2 from flask_sqlalchemy import SQLAlchemy 5 6 app = Flask(__name__,static_url_path='') 7 app.debug = True 8 app.secret_key = "faefasdfaf" 9 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./db/personal.db' # app的配置,指定數(shù)據(jù)庫路徑10 app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True11 app.config['SQLALCHEMY_ECHO'] = True 12 13 db = SQLAlchemy(app)
然后我們利用db創(chuàng)建員工表: