@manager.option('-n', '-name', dest='name')
@manager.option('-p', '-password', dest='password')
def createsuperuser(name, password):
"""创建管理员用户"""
if not all([name, password]):
print('参数不足')
return
user = User()
user.mobile = name
user.nick_name = name
user.password = password
user.is_admin = True
try:
db.session.add(user)
db.session.commit()
print("创建成功")
except Exception as e:
print(e)
db.session.rollback()
终端执行:
$ python manage.py createsuperuser -n admin -p 12345678
当前名称:Flask中超级用户的创建与使用
文章起源:
http://njwzjz.com/article/psoceg.html