标签:api alc svi data ESS install style pymysql 导入
pip3 install flask_admin
from flask import Flask from flask_admin import Admin app = Flask(__name__) #将app注册到adminzhong admin = Admin(app) if __name__=="mian": app.run() #访问 #127.0.0.1:5000/admin端口,会得到一个空白的页面
#在将表注册之前应该对app进行配置 SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:@127.0.0.1:3307/py9api?charset=utf8mb4" SQLALCHEMY_POOL_SIZE = 5 SQLALCHEMY_POOL_TIMEOUT = 30 SQLALCHEMY_POOL_RECYCLE = -1 #导入models文件的中的表模型 from flask_admin.contrib.sqla import ModelView from api.models import Stock,Product,Images,Category,Wxuser,Banner admin.add_view(ModelView(Stock, db.session)) admin.add_view(ModelView(Product, db.session)) admin.add_view(ModelView(Category, db.session))
#配置上传文件的路径 #导入from flask_admin.contrib.fileadmin import FileAdmin from flask_admin.contrib.fileadmin import FileAdmin,form file_path = op.join(op.dirname(__file__), ‘static‘) admin = Admin(app) admin.add_view(FileAdmin(file_path, ‘/static/‘, name=‘文件‘)) #如果有个字段要是上传文件重写该方法的modleView类,假设imgae_url是文件图片的字段 class ImagesView(ModelView): form_extra_fields = { ‘image_url‘: form.ImageUploadField(‘Image‘, base_path=file_path, relative_path=‘uploadFile/‘ ) } admin.add_view(ImagesView(Images, db.session))
标签:api alc svi data ESS install style pymysql 导入
原文地址:https://www.cnblogs.com/wangyong123/p/11830796.html