flask添加用户,需要通过在fabmanager命令来添加用户,写入框架的db数据库中,然后登陆时页面写入的用户名密码会同数据库中数据进行确认授权
具体过程如下“
1. 激活虚拟环境,查询现有用户信息,以便后续确认是否添加成功
需要先使用acticvate.bat将虚拟环境运行起来,然后通过cd命令进入到run.py所在目录,使用fabmanager 命令查询用户信息,确认当前新加用户是否已经存在
fabmanager list-users查询数据库中已有数据:
List of users
-------------
username:test_1 | email:vend_auto_nb001@aaa.com | role:[Admin]
username:autotest | email:jackey.ma@aaa.com | role:[Public]
2. 用户信息添加,
通过使用fabmanager create-admin来添加管理员权限用户
(Python37env) ? fabmanager create-admin
fabmanager is going to be deprecated in 2.2.X, you can use the same commands on the improved ‘flask fab <command>‘
Username [admin]: aaa
User first name [admin]: bbb
User last name [user]: accc
Email [admin@fab.org]: ddd@eee.com
Password:
Repeat for confirmation:
Recognized Database Authentications.
2021-07-21 10:42:46,670 - manager.py[line:191] - INFO: Added user aaa
Admin User aaa created.
这样admin用户已经添加完成
3. 常用fabmanager命令
常用fabmanager命令:
Commands:
babel-compile Babel, Compiles all translations
babel-extract Babel, Extracts and updates all messages marked for...
collect-static Copies flask-appbuilder static files to your projects...
create-addon Create a Skeleton AddOn (needs internet connection to...
create-admin Creates an admin user
create-app Create a Skeleton application (needs internet
connection...
create-db Create all your database objects (SQLAlchemy specific).
create-user Create a user
list-users List all users on the database
list-views List all registered views
reset-password Resets a user‘s password
run Runs Flask dev web server.
security-cleanup Cleanup unused permissions from views and roles.
version Flask-AppBuilder package version