HTML 原文 · 完整 Markdown · 纯文本 · 分段目录 · ← 上一段 · 下一段 →

01-FastAPI 项目结构怎么设计,才能在功能变多后不失控

第 7 / 12 段:跨模块调用时,不要偷懒

FastAPI 工程化实践 · 发布 2026-03-28 · 更新 2026-11-11 · 标签:FastAPI、Python、Architecture

跨模块调用时,不要偷懒

当一个模块依赖另一个模块时,尽量使用显式导入,而不是模糊导入。

from src.auth import constants as auth_constants
from src.posts.service import publish_post

这样做的好处很直接: