初识Flask
一、Django与Flask的区别
Django: 大而全
Flask:短小精悍、可扩展性强
共同点:都是借助第三方组件实现wsgi
Django:wsgiref
Flask: werkzeug
二、基于werkzeug的Hello World项目
from werkzeug.wrappers import Request, Response from werkzeug.serving import run_simple @Request.application def hello(request): return Response('Hello World') if __name__ == '__main__': run_simple('localhost', 4000, hello)
三、基于Flask的Hello World项目
from flask import Flask app = Flask(__name__) @app.route('/index') def index(): return "Hello World" if __name__ == '__main__': app.run()