flaskweb
flaskweb copied to clipboard
An easy to start yet full-featured web framework
Flaskweb
An easy to start yet full-featured web framework
- Installation
- Quickstart
- Features
- more todos
- Tutorial
- 10分钟速成版
- Serious python web developer version
👽
- Development
- Distribution
- Thanks
Installation
pip install -U flaskweb
# or git clone and install; git pull for later updates
git clone [email protected]:Meteorix/flaskweb.git
pip install -e flaskweb
Quickstart
基本语法与flask几乎一样,几行代码即可构建一个web服务器
from flaskweb.app import create_app, gevent_run
from flask import render_template
app = create_app("debug")
@app.route("/")
def index():
return render_template("debug.html")
if __name__ == "__main__":
gevent_run(app)
不一样的地方在于,上面的web服务器自带:
- 用户登录系统
- orm/migrate
- db管理页面
- swaggerui
- gevent服务器
![]() |
![]() |
![]() |
![]() |
try it:
cd simple
# 初始化数据库,会保存到simple/app.db
flask db init
flask db upgrade
flask db migrate
# 运行gevent服务器
python -u app.py
then visit http://127.0.0.1:5000/
A more sophisticated example
Features
- flask
- sqlalchemy
- config
- logger
- user login
- db admin
- restful api with swagger ui
- gevent
- use as a 3rd library
- frontend with bootstrap/jquery
- setup.py for distribution
- cythonize
- gunicorn
more todos
- celery
- nginx
- more samples: tensorflow/pytorch webapp
- jwt
- pyinstaller
- dockerfile
- performance/benchmark
Tutorial
10分钟速成版
假设你有python和flask基础,介绍如何利用flaskweb速成
-
创建新的项目
将example目录copy到你的项目中,作为启动模板
-
定义url,返回默认html页面
@app.route("/") def index(): return render_template(debug.html)启动服务器,访问 http://127.0.0.1:5000/
python wsgi.py -
创建sqlite数据库,使用内置的用户登录系统
cd simple # 初始化数据库,会保存到simple/app.db flask db init flask db migrate flask db upgrade重启服务器,访问登陆页面 http://127.0.0.1:5000/login
-
当然你需要先注册用户
在注册页面上注册好之后,
debug模式运行会自动激活账号,直接登录非
debug模式需要找管理员激活账号:管理员访问admin页面 http://127.0.0.1:5000/admin/user,勾选用户的active属性 -
定义数据库orm,使用admin页面管理
参考 example/models.py
-
定义restful api,使用swagger ui调试
python代码参考 example/views.py, api spec参考OpenAPI
访问 http://127.0.0.1:5000/apidocs/ 调试API,调试好就可以给前端工程师开发前端了
-
前端工程师输出前端代码
- html文件放到
templates目录 - 其他文件放到
static目录
- html文件放到
-
10分钟差不多都学会啦
Serious python web developer version :alien:
- python basics
- flask quickstart
- sql基础
- html/css/js基础
- restful api规范
- ...
- http/tcp协议《http权威指南》
- linux知识《APUE》
- ...
Development
Develop flaskweb framework
virtualenv venv
source venv/bin/activate
pip install -r requirements
Build and upload to pypi
python setup.py build
python setup.py sdist
pip install twine # for pypi upload
python -m twine upload dist/...
Distribution
Distribute example project using setup.py
cd example
python setup.py build
python setup.py sdist --formats=zip
Or cythonize and dist as wheel for better encryption
python setup.py bdist_wheel
todo: pyinstaller
Thanks
- https://github.com/miguelgrinberg/flasky
- https://github.com/JackStouffer/Flask-Foundation



