FastAPI 教程翻译 - 用户指南 1 - 简介

本教程逐步引导您使用FastAPI框架,涵盖其大部分功能。通过实际代码示例,您将学会构建API,体验FastAPI带来的类型检查、自动补全等优势。适合初学者至进阶者,教程结构清晰,便于按需查阅。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FastAPI 教程翻译 - 用户指南 1 - 简介

FastAPI Tutorial - User Guide - Intro

This tutorial shows you how to use FastAPI with most of its features, step by step.

本教程将逐步向您展示如何使用 FastAPI 及其大部分功能。

Each section gradually builds on the previous ones, but it’s structured to separate topics, so that you can go directly to any specific one to solve your specific API needs.

每个部分都逐步建立在前面部分的基础上,但是它的结构是单独的主题,因此您可以直接进入任何特定的主题来解决您特定的 API 需求。

It is also built to work as a future reference.

它也可以作为将来的参考。

So you can come back and see exactly what you need.

这样您就可以回来,确切地了解您的需求。

Run the code

运行代码

All the code blocks can be copied and used directly (they are actually tested Python files).

所有代码块都可以直接复制和使用(它们实际上是经过测试的 Python 文件)。

To run any of the examples, copy the code to a file main.py, and start uvicorn with:

要运行任何示例,请将代码复制到文件 main.py 中,然后使用以下命令启动 uvicorn

uvicorn main:app --reload

It is HIGHLY encouraged that you write or copy the code, edit it and run it locally.

强烈建议您编写或复制代码,对其进行编辑并在本地运行。

Using it in your editor is what really shows you the benefits of FastAPI, seeing how little code you have to write, all the type checks, autocompletion, etc.

在编辑器中使用它确实可以为您显示 FastAPI 的好处,可以看到您只需编写很少的代码,并拥有类型检查和自动补全等。


Install FastAPI

安装 FastAPI

The first step is to install FastAPI.

第一步,安装 FastAPI。

For the tutorial, you might want to install it with all the optional dependencies and features:

对于本教程,您可能需要安装所有可选的依赖项和功能:

pip install fastapi[all]

…that also includes uvicorn, that you can use as the server that runs your code.

…… 还包括 uvicorn,您可以将其用作运行代码的服务器。

Note

注意

You can also install it part by part.

您也可以部分安装。

This is what you would probably do once you want to deploy your application to production:

要将应用程序部署到生产环境中,可能会需要执行以下操作:

pip install fastapi

Also install uvicorn to work as the server:

同时安装 uvicorn 以用作服务器:

pip install uvicorn

And the same for each of the optional dependencies that you want to use.

并且对于要使用的每个可选依赖项都进行相同操作。

Advanced User Guide

高级用户指南

There is also an Advanced User Guide that you can read later after this Tutorial - User guide.

还有一个高级用户指南,您可以在本用户指南之后阅读。

The Advanced User Guide, builds on this, uses the same concepts, and teaches you some extra features.

以此为基础的高级用户指南使用相同的概念,并教给您一些额外的功能。

But you should first read the Tutorial - User guide (what you are reading right now).

但是,您首先应该阅读用户指南(现在正在阅读的内容)。

It’s designed so that you can build a complete application with just the Tutorial - User guide, and then extend it in different ways, depending on your needs, using some of the additional ideas from the Advanced User Guide.

它经过专门设计,因此您可以仅使用用户指南来构建完整的应用程序,然后根据您的需要,使用高级用户指南中的一些其他想法,以不同的方式扩展它。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值