首先就是安装FastAPI
# 方式1
pip install "fastapi[all]"
# 方式2 分开来安装
pip install fastapi
pip install "uvicorn[standard]"
# ... 需要什么再安装什么
-
最简单的 FastAPI 文件可能像下面这样(main.py)
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
# 生产环境-运行命令没有 --reload
uvicorn main:app --reload --host 0.0.0.0 --port 80
参数 |
含义 |
main |
main.py 文件(一个 Python「模块」),也可以是xxx.main:app |
app |
在 main.py文件中通过 app = FastAPI() 创建的对象 |
--reload |
让服务器在更新代码后重新启动。仅在开发时使用该选项 |
--host 0.0.0.0 |
监听所有 IP 地址 |
--port 80 |
监听 80 端口 |
本文标题:首先就是安装FastAPI
本文链接:https://www.haomeiwen.com/subject/chngcjtx.html
网友评论