Which Python web framework has a short learning cycle and low learning cost?

王林
Release: 2023-04-12 09:13:06
forward
1348 people have browsed it

Someone asked on Zhihu, which web framework of Python has a short learning cycle and low learning cost?

Which Python web framework 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.

Why do we say fast, simple and strong?

  • First of all, FastApi takes advantage of asynchronous and lightweight features, and uses strong typing, which greatly improves performance and is even comparable to GO and NodeJS;
  • Secondly, it can quickly program and artificially Few bugs, low debugging costs, and simple design can increase the web construction speed by 2-3 times, making it very suitable for novices to operate.

What are the similarities and differences between it and Django?

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.

Case

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}
Copy after login

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.
Copy after login

Enter http://127.0.0.1:8000/docs, you will see Automatically generated interactive API documentation.

Which Python web framework has a short learning cycle and low learning cost?

Learning documentation: https://fastapi.tiangolo.com

Which Python web framework has a short learning cycle and low learning cost?

GIthub address: https://github .com/tiangolo/fastapi

Which Python web framework has a short learning cycle and low learning cost?

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!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!