单个脚本编写小型 Web应用很方便,但是伸缩性不好,难以扩展和维护。

    本文介绍一种常见的前后端分离项目的结构设计。

    1. |- your_project
    2. |- app
    3. |- commons # 公共方法
    4. |- config # 配置文件
    5. |- config_live.json
    6. |- config_local.json
    7. |- enum # 配置枚举值
    8. |- business_enum.py
    9. |- models # 模型类
    10. |- __init__.py # 将models 这个文件夹变成 Python module
    11. |- student
    12. |- student.py
    13. |- resources # 接口
    14. |- __init__.py
    15. |- student
    16. |- __init__.py
    17. |- student_api.py
    18. |- service # view logic,视图逻辑,主要封装业务逻辑处理
    19. |- __init__.py
    20. |- student.py
    21. |- utils # 工具库
    22. |- __init__.py
    23. |- tools.py
    24. |- dockerfiles # 容器化部署
    25. |- Dockerfile
    26. |- requirements.txt

    /