- pip3 install flask
- Web框架:
- 路由
- 視圖
- 模板渲染
- flask中無socket,依賴 實現wsgi協議的模塊: werkzeug
- URL兩種添加方式:
方式一:
@app.route('/xxxxxxx')
def hello_world():
return 'Hello World!'
方式二:
def index():
return "Index"html
app.add_url_rule('/index',view_func=index)
- 路由系統:
- 固定
@app.route('/x1/')
def hello_world():
return 'Hello World!'redis
- 不固定
@app.route('/user/<username>')
@app.route('/post/<int:post_id>')
@app.route('/post/<float:post_id>')
@app.route('/post/<path:path>')
@app.route('/login', methods=['GET', 'POST'])sql
@app.route('/xx/<int:nid>')
def hello_world(nid):
return 'Hello World!'+ str(nid)
- 自定製正則
@app.route('/index/<regex("\d+"):nid>')
def index(nid):
return 'Index'
- 視圖
- 模板
- message
- 中間件
- Session
- 默認:加密cookie實現
- 第三方:Flask-Session
redis: RedisSessionInterface
memcached: MemcachedSessionInterface
filesystem: FileSystemSessionInterface
mongodb: MongoDBSessionInterface
sqlalchemy: SqlAlchemySessionInterface
- 藍圖(文件夾的堆放)
- 安裝第三方組件:
- Session: Flask-Session
- 表單驗證:WTForms
- ORM: SQLAchemy
參考博客:http://www.cnblogs.com/wupeiqi/articles/7552008.html
4. Tornado
- pip3 install tornado
參考博客:http://www.cnblogs.com/wupeiqi/articles/5702910.htmlmongodb