Python开发框架不少,Flask,Django之前在工作中都已用过,Flask比较轻量,Django功能全面但有点重,Sanic感觉是Flask的加强版,是专注于异步的高性能Python Web框架。Sanic用法和Flask十分相似。
# Django from django.http import HttpResponse def hello_world(request): return HttpResponse("Hello, World!") # Flask from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run() # Sanic from sanic import Sanic from sanic.response import text app = Sanic() @app.route("/") async def hello_world(request): return text("Hello, World!") if __name__ == "__main__": app.run(host="0.0.0.0", port=8000)
这次使用的是 Sanic + Tortoise ORM + VUETIFY,前端还看了下华为云开源的 OpenTiny 组件库,感觉不错,以后有机会用用,Mark下。
Sanic User Guide - The lightning-fast asynchronous Python web framework
mekicha/awesome-sanic: A curated list of awesome Sanic resources and extensions
Build optimized websites quickly, focus on your content | Docusaurus