article

Friday, February 14, 2020

Flash-Admin intro using sqlite SQLAlchemy


Flash-Admin into using sqlite SQLAlchemy

install flask admin from pip


pip install flask-admin


 
#app.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///admin.db'
app.config['SECRET_KEY'] = 'cairocoders-ednalan'

db = SQLAlchemy(app)

# set optional bootswatch theme
app.config['FLASK_ADMIN_SWATCH'] = 'darkly'

admin = Admin(app, name='microblog', template_mode='bootstrap3')
# Add administrative views here

class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30))

admin.add_view(ModelView(Person, db.session))

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

Related Post