Django React 项目结构

Django React project structure

我有一个以 Django 作为后端的项目。

对于客户端,我有 4 个不同的部分:

我脑子里的结构是这样的:

├── djangoproject
│   ├── __init__.py
│   ├── settings.py (can be folder)
│   ├── urls.py
│   └── wsgi.py
├── apps
|   ├── admin_panel
|   ├── core
|   ├── auth
|   └── ...
├── templates
|   ├── admin_panel (react)
|   ├── core (react)
|   └── auth
├── static
└── manage.py

我有两个问题:

1- 我是否应该更改我的项目结构(例如将 React 文件夹移到外部或使用前端文件夹命名而不是模板?)

2- 对 React 应用程序使用 git 子模块 并且只在主项目中提交它们的构建是否常见(或合理)?如果是,你能举出任何例子或最佳实践吗?

为了项目结构的最佳实践,我认为你应该在后端存储库(文件夹)之外为前端(react)创建一个不同的存储库(文件夹)。

后端结构

我遵循这个项目结构:

├──djangoproject
|
|__config
|  |
|  |__settings
|  |  | 
|  |  |__base.py
|  |  |__local.py
|  |
|  |__urls.py
|  |__wsgi.py
|  |__ __init__.py
|
|__djangoproject
|  |
|  |__users (user app dirctory)
|  |__products (product app dirctory)
|  |__ __init__.py
|
|
|__static
|  |
|  |__css
|  |__js
|
|__media
|
|__manage.py
|__gitignore

前端结构

├──djangoproject(React)
|
|__app
|  |
|  |__assests
|  |  | 
|  |  |__fonts
|  |  |__images
|  |
|  |__components
|  |  |__your components
|  |__containers
|  |  |__Your containers
|  |__app.js
|
|
|__README.md
|
|__package.json
|__gitignore

为了更好地理解项目结构,我建议您在前端使用 Django cookie cutter (https://cookiecutter-django.readthedocs.io/en/latest/index.html) for back-end and use react boilerplate (https://www.reactboilerplate.com/)。