使用說明:
1.安裝
pip?install?Flask-Admin
pip?install?Flask-SQLAlchemy
pip?install?Flask-Security
pip?install?flask-xadmin
2.整合
可以參考作者在2016.12月寫的例子
.readthedocs.io/zh_CN/latest/models.html)
app.config['SECURITY_PASSWORD_HASH']和app.config['SECURITY_PASSWORD_SALT']是必須的
password字段的長度不得低於120,User模型裏的所有字段char長度之和不能超過1000
其他地方直接照搬例子即可。
其中要註意的是
views=[
myModelView(model=User,session=db.session,category='Entities'),
myModelView(model=Role,session=db.session,category='Entities'),
myModelView(model=Mydata,session=db.session,category='Entities'),
myFileAdmin(base_path='.',name="Files",category='Files']
需要修改,在category屬性後面再添加endpoint屬性,即:
views=[
myModelView(model=User,session=db.session,category='Entities',endpoint="User"),
myModelView(model=Role,session=db.session,category='Entities',endpoint="Role"),
myModelView(model=Mydata,session=db.session,category='Entities',endpoint="Mydata"),
myFileAdmin(base_path='.',name="Files",category='Files',endpoint="files")]
不然會報錯藍圖重復錯誤:
AssertionError: A blueprint's name collision occurred between and . Both share the same name "workflow". Blueprints that are created on the fly need unique names.