django - Django REST Framework 应用程序真的必须是项目根应用程序文件夹的子文件夹吗?

标签 django django-rest-framework

我正在仔细阅读 Django REST 框架学习 Material ,但有些事情让我产生了疑问。

我注意到在 Quickstart page ,他们建议将应用程序创建为根应用程序文件夹的子文件夹(使用命令 django-admin.py startproject tutorial 末尾的点。):参见此 image of the Quickstart folder structure .

但是Tutorial首先创建普通的 Django 文件夹结构:app 文件夹直接放在项目文件夹中(因此,不是根 app 文件夹的子文件夹):参见 image of the Tutorial folder structure .

Quickstart 页面通过声明有必要避免名称冲突来捍卫其构建文件夹的方式。如果这是最佳实践或只是避免我的项目崩溃的必要条件,我只是不明白为什么教程不以这种最佳实践文件夹结构开始。

有人可以澄清这种“最佳实践”奇数文件夹重组(如快速入门页面)是否真的有必要吗?在学习完 Django REST 框架后,我要建立一个真正的项目,我想知道我是否可以坚持我习惯的正常文件夹结构(如教程示例中),还是不是。

亲切的问候。

最佳答案

,所有应用都必须在主项目文件夹中。

如果你开始一个 Django 项目

django-admin startproject myproject

它应该有这样的结构:

myproject
   |
   |----myproject
   |      |----__init__.py
   |      |----settings.py
   |      |----urls.py
   |      |----wsgi.py
   |
   |----customapp1
   |      |-----migrations folder
   |      |-----templates folder
   |      |-----static folder
   |      |-----__init__.PY
   |      |-----models.py
   |      |-----views.py
   |      |-----other files
   |
   |----customapp2
   |      |-----migrations folder
   |      |----- all other files and folders
   |
   |----cutomapp3 and etc.......

关于django - Django REST Framework 应用程序真的必须是项目根应用程序文件夹的子文件夹吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624307/

相关文章:

Django:测试模板是否继承了正确的模板

python - django多个具有相同模型和外键的ModelForm

python - "http method not bound to view"在 drf_yasg 中记录基于类的 View 时

python - 当我执行 Trades Record.objects.create(**traderecord_data) 时,会引发 TypeError

django - 在 base.html (django) 中显示登录用户

Django 渲染模板对象错误

python - Django Rest Framework 实例化序列化器错误

json 中的 Django REST 框架 url

python - 如何设计处理离线数据的rest api

python - 模型子类: override CharField max_length