1. code reuse


要多利用 module structure,

---module

  ------ __init__ 

  ------module.py


 这个结构可以让module 顺利的导入到很多code利用中。


2. Flask  windows 下production deployment server, 有两个WSGI server 可以用, waitress, cheroot WSGI server(最好install cherrypy)




from flask import Flask, escape, request
from waitress import serve
from cheroot.wsgi import PathInfoDispatcher
from cheroot.wsgi import Server as WSGIServer

app = Flask(__name__)

@app.route('/')
def hello():
    name = request.args.get("name", "World")
    return f'Hello, {escape(name)}!'
 
def production_server(flask_app):
    production_dis=PathInfoDispatcher({'/':flask_app})
    return WSGIServer(('0,0,0,0', 8088), production_dis, numthreads=10)

if __name__=='__main__':
   # waitress to fire flask
   serve(app, host='0,0,0,0', port=8088, threads=10)
   
   # cheroot to serve
   production_server(app).start()