目录
目录README.md

FastApiModuleTemplate

1.简介

FastApi 模块工程模板。

2.使用说明

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

2.1.工程目录

.
├── fast_api_module_template        # 子模块名
│   ├── dependencies                # 依赖项模块
│   │   ├── __init__.py
│   │   ├── authorization.py        # 授权依赖
│   ├── docs                        # 相关文档与手册
│   │   ├── manual.md               # 手册文档
│   ├── items                       # 数据结构模块
│   │   ├── __init__.py
│   │   ├── user.py                 # 用户数据结构
│   ├── logs                        # 日志文件
│   │   ├── debug.log               # 调试日志
│   ├── routers                     # 路由模块
│   │   ├── __init__.py
│   │   ├── hello_world.py          # hello_world 子路由
│   ├── statics                     # 静态资源文件
│   │   ├── icons                   # 图标
│   │   │   ├── favicon.svg         # favicon 图标
│   ├── templates                   # HTML 模板文件
│   │   ├── index.html              # index 网页模板
│   └── utils                       # 第三方、工具、常量、异常等公用工具模块
│   │   ├── __init__.py
│   │   └── log_util.py             # 日志工具
│   ├── __init__.py
│   ├── .gitignore                  # 启停或其他脚本
│   ├── main.py                     # 启动项目入口文件
│   ├── readme.md                   # 项目说明文档
│   ├── requirements.txt            # 项目运行环境依赖包
│   ├── restart.sh                  # 重启脚本
│   ├── start.sh                    # 启动脚本
│   ├── stop.sh                     # 停止脚本

2.2.启动步骤

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

hello_world_router = APIRouter()


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

hello_world_app.include_router(hello_world.hello_world_router)
  • 最后,使用 uvicorn 启动应用
cd ..

uvicorn FastApiModuleTemplate.app:hello_world_app --host 0.0.0.0 --port 8080 --reload

3.注意事项

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

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

参考文档

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

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