Someone asked on Zhihu, which web framework of Python has a short learning cycle and low learning cost?
Many people recommend Flask, an old lightweight web framework, which is indeed the first choice for beginners. I saw FastApi on Github these days and thought it was more lightweight than Flask.
FastApi is an Internet celebrity web framework that has suddenly emerged in the past two years and is suitable for novices to get started quickly. .
In general, FastAPI has three advantages: fast, simple, and powerful.
Its self-label is:
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6 based on standard Python type hints.
Compared with Django, FastAPI is a lightweight web framework.
Django is battery included. Although it is troublesome to configure, it comes with many functions by default, including useful ORM and migration tools, as well as many security middleware, etc. There are also template systems, static resource management systems, etc. For general business websites, Django can be used out of the box.
FastAPI is very lightweight. It comes with nothing, no ORM, no migration, no middleware, nothing. This is a disadvantage as well as an advantage.
main.py:
from typing import Optional from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") def read_item(item_id: int, q: Optional[str] = None): return {"item_id": item_id, "q": q}
Run the server:
$ uvicorn main:app --reload INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [28720] INFO: Started server process [28722] INFO: Waiting for application startup. INFO: Application startup complete.
Enter http://127.0.0.1:8000/docs, you will see Automatically generated interactive API documentation.
Learning documentation: https://fastapi.tiangolo.com
GIthub address: https://github .com/tiangolo/fastapi
The above is the detailed content of Which Python web framework has a short learning cycle and low learning cost?. For more information, please follow other related articles on the PHP Chinese website!