Skip to content
An easy to start yet full-featured web framework
Branch: master
Clone or download
Latest commit 4489f65 Apr 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs/images add docs/images Apr 15, 2019
example add setup.py for example Apr 16, 2019
flaskweb even longer password... Apr 19, 2019
simple add simple example Apr 13, 2019
.gitignore
MANIFEST.in add setup.py for dist Apr 15, 2019
README.md update readme Apr 16, 2019
requirements.txt mv todoapp out Apr 11, 2019
setup.py level up to 0.0.5 Apr 16, 2019

README.md

Flaskweb

An easy to start yet full-featured web framework

Installation

pip install -U flaskweb

# or git clone and install; git pull for later updates
git clone git@github.com: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("main.html")

if __name__ == "__main__":
    gevent_run(app)

不一样的地方在于,上面的web服务器自带:

  • 用户登录系统
  • orm/migrate
  • db管理页面
  • restapi/swaggerui
  • gevent服务器
main !login
!api !admin

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
  • gunicorn/gevent deployment
  • use as a 3rd library
  • frontend with bootstrap/jquery
  • setup.py for distribution

more todos

  • deployment: nginx/gunicorn
  • more samples: tensorflow/pytorch webapp
  • jwt
  • cythonize
  • pyinstaller
  • dockerfile
  • performance/benchmark

Tutorial

10分钟速成版

假设你有python和flask基础,介绍如何利用flaskweb速成

  1. 创建新的项目

    example目录copy到你的项目中,作为启动模板

  2. 定义url,返回默认html页面

    @app.route("/")
    def index():
        return render_template("main.html")

    启动服务器,访问 http://127.0.0.1:5000/

    python wsgi.py
  3. 创建sqlite数据库,使用内置的用户登录系统

    cd simple
    # 初始化数据库,会保存到simple/app.db
    flask db init
    flask db migrate
    flask db upgrade

    重启服务器,访问登陆页面 http://127.0.0.1:5000/login

  4. 当然你需要先注册用户

    在注册页面上注册好之后,debug模式运行会自动激活账号,直接登录

    debug模式需要找管理员激活账号:管理员访问admin页面 http://127.0.0.1:5000/admin/user,勾选用户的active属性

  5. 定义数据库orm,使用admin页面管理

    参考 example/models.py

  6. 定义restful api,使用swagger ui调试

    参考 example/views.py

    访问 http://127.0.0.1:5000/swagger/ 调试API,调试好就可以给前端工程师开发前端了

  7. 前端工程师输出前端代码

    • html文件放到templates目录
    • 其他文件放到static目录
  8. 10分钟差不多都学会啦

Serious python web developer version 👽

  1. python basics
  2. flask quickstart
  3. sql基础
  4. html/css/js基础
  5. restful api规范
  6. ...
  7. http/tcp协议《http权威指南》
  8. linux知识《APUE》
  9. ...

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

todo: cythonize/bdist_wheel & pyinstaller

Thanks

You can’t perform that action at this time.