标签:session rollback not create superuser dmi ack use option
@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
标签:session rollback not create superuser dmi ack use option
原文地址:http://blog.51cto.com/13914991/2175871