目录
目录README.md

<<<<<<< HEAD

FastApiModuleTemplate

1.简介

FastApi 模块工程模板。

2.使用说明

本仓库 FastApiModuleTemplateFastApi 应用子模块工程模板。 该工程可以 独立开发独立运行,并在必要时,可以由 FastApi 应用 引用集成。

2.1.工程目录

.
├── FastApiModuleTemplate           # 子模块名
│   ├── dependencies                # 依赖项模块
│   │   ├── __init__.py
│   │   ├── authorization.py        # 授权依赖
│   ├── docs                        # 相关文档与手册
│   │   ├── manual.md               # 手册文档
│   ├── items                       # 数据结构模块
│   │   ├── __init__.py
│   │   ├── user_item.py            # 用户数据结构
│   ├── logs                        # 日志文件
│   │   ├── .gitkeep
│   ├── models                      # 数据库 ORM 模块
│   │   ├── __init__.py
│   ├── routers                     # 路由模块
│   │   ├── __init__.py
│   │   ├── swagger_router.py       # swagger 子路由,请勿删除
│   │   ├── hello_world_router.py   # hello_world 子路由
│   ├── services                    # 服务逻辑模块
│   │   ├── __init__.py
│   ├── settings                    # 配置模块
│   │   ├── __init__.py
│   │   ├── directory_config.py     # 目录配置
│   ├── statics                     # 静态资源文件
│   │   ├── icons                   # 图标
│   │   │   ├── favicon.svg         # favicon 图标
│   ├── templates                   # HTML 模板文件
│   │   ├── .gitkeep
│   ├── temps                       # 缓存目录
│   │   ├── .gitkeep
│   └── utils                       # 第三方、工具、常量、异常等公用工具模块
│   │   ├── __init__.py
│   │   └── log_util.py             # 日志工具
│   ├── __init__.py
│   ├── .gitignore
│   ├── app.py                      # 启动项目入口文件
│   ├── LICENSE                     # 共享许可证
│   ├── README.md                   # 项目说明文档
│   ├── requirements.txt            # 项目运行环境依赖包
│   ├── restart.sh                  # 重启脚本
│   ├── start.sh                    # 启动脚本
│   ├── stop.sh                     # 停止脚本

2.2.启动步骤

  • 首先,在 routers 目录下编写子路由逻辑
from fastapi import APIRouter

router = APIRouter()


@router.get("/")
async def do_hello_world():
    return "Hello World!"
  • 其次,在 app.py 引入子路由
from .routers import hello_world_router

app.include_router(hello_world_router.router)
  • 最后,使用 uvicorn 启动应用
uvicorn FastApiModuleTemplate.app:app --host 0.0.0.0 --port 8080 --reload

3.注意事项

  • Python 开发 时,请使用 相对引用

  • FastApi 使用 APIRouter 子路由构建路径

参考文档

https://github.com/swagger-api/swagger-ui

https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css

https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js

https://fastapi.tiangolo.com/img/favicon.png

Comment_Information_Collection

f2de3d5ead524c4a16a39f5ed6dbf7dca186cff7

关于
538.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号