Common Django Project structures - Part 2

Yesterday we saw the simplest and default pattern for the layout of a Django project. Today we will have a look at the another common layout for larger projects.

This project structure groups all of the apps under a single common directory. This provides a clear boundary of what is an app and what is project based which some might find confusing in the yesterday's setup.

Here is an example directory structure:

├── db.sqlite3
├── manage.py
├── project
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── apps
    ├── app1
    │   ├── __init__.py
    │   ├── admin.py
    │   ├── apps.py
    │   ├── migrations
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   └── views.py
    └── app2
        ├── __init__.py
        ├── admin.py
        ├── apps.py
        ├── migrations
        │   └── __init__.py
        ├── models.py
        ├── tests.py
        └── views.py

This structure allows any number of apps to be situated under the apps directory without cluttering the project root.

The key thing for this setup is that you need to set the name attribute in your AppConfig and in INSTALLED_APPS to be "apps.app1" like so:

class MyAppConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "apps.app1"
INSTALED_APPS = [
  ...
  "apps.app1",
]

Where app1 is the current app name so the second app would have the value "apps.app2".

Tomorrow I will show what structure you can do for the simplest of projects.