def create_admin(name, password, email): """ 设置管理员 :param name: :param password: :param email: :return: """ with db.auto_commit(): admin = Admin() admin.name = name admin.password = password admin.email = email admin.avatar = '/static/admin/images/guest.png' admin.role = Role.query.get(1) db.session.add(admin) print("成功添加管理员,用户名:%s 密码:%s 邮箱:%s" % (name, password, email))
# -*- coding: utf-8 -*- """ @description: @copyright: (c) 2019/3/28 18:17 by Henry. """ from datetime import datetime __author__ = 'Henry' from app import create_app from app.models.base import db from app.models.admin import Admin app = create_app() with app.app_context(): with db.auto_commit(): # 创建一个超级管理员 user = Admin() user.nickname = 'Admin' user.username = '******' user.password = '******' user.email = '*****@*****.**' db.session.add(user)