Flask --- another lightweight Web framework of Python
Flask is another lightweight Web framework in Python. on github, there are close to 15000 star. github addresses: Flask
Its usage is very similar to that of Bottle. If you are interested, refer to the lightweight http server of Bottle-Python.
#-*-Coding: UTF-8 -*-#! /Usr/bin/pythonfrom flask import Flask, jsonifyapp = Flask (_ name _) @ app. route ('/') def index (): return 'index' # Use
Pass the parameter @ app. route ('/hello/
') Def hello_get (user): return 'Hello get % s' % user # Use POST request @ app. route ('/hello/
', Methods = ['post']) def hello_post (user): return 'Hello POST % s' % user@app.route ('/hotCity ') def hotCity (): cities = ['beijing', 'shanghai', 'guangzhou '] return jsonify ({'code': 0, 'Cities': cities ,}) if _ name _ = '_ main _': app. run () # You can also debug in the browser # app. run (debug = True)
Unlike Django, Flask can modify code without restarting HTTP Server.