Flask-Admin是一个功能齐全、简单易用的Flask扩展,让你可以为Flask应用程序增加管理界面。它受django-admin包的影响,但用这样一种方式实现,开发者拥有最终应用程序的外观、感觉和功能的全部控制权。

重点模块

模块名 简介
Flask_admin As a micro-framework, Flask lets you build web services with very little overhead. It offers freedom for you, the designer, to implement your project in a way that suits your particular application.
Bootswatch Bootswatch主题来自定义外观
Flask-SQLAlchemy Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.
Flask-BabelEx Flask-BabelEx is an extension to Flask that adds i18n and l10n support to any Flask application with the help of babel, pytz and speaklater. It has builtin support for date formatting with timezone support as well as a very simple and friendly interface to gettext translations.
WTForms With WTForms, your form field HTML can be generated for you, but we let you customize it in your templates. This allows you to maintain separation of code and presentation, and keep those messy parameters out of your python code. Because we strive for loose coupling, you should be able to do that in any templating engine you like, as well.
Flask-Login Flask-Login 为 Flask 提供了用户会话管理。它处理了日常的登入,登出并且长时间记住用户的会话。

环境准备

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#新建用户
useradd myweb
passwd myweb

#新建项目目录QingYu
su - myweb
mkdir QingYu

#安装软件包
#从myweb用户退出,登陆为root用户后执行以下步骤:
yum install -y epel-release
yum -y install python-pip
pip install -upgrade pip

#安装python模块flask-admin
su - myweb
cd QingYu
vim manage.py

#运行程序
python manage.py

数据库准备

1
2
3
4
5
6
7
8
#创建数据库myweb
mysql -e "create database myweb"

#添加应用程序授权
#修改root密码,应用程序将使用本地root用户的权限。如果你熟悉数据库,可以将新建一个小权限的数据库用户。
mysql -uroot -pmyweb myweb -e "drop table AdminUser;"
mysql -uroot -pmyweb myweb -e "create table user (id int primary key auto_increment,first_name varchar(100),last_name varchar(100),login varchar(80),email varchar(120),password varchar(64));"
mysql -uroot -pmyweb myweb -e "alter table user add unique index idx_login (login);"

通过浏览器登陆访问 http://192.168.206.139:5000/admin

效果图如下:

代码

程序代码会持续更新