[Django] #36113: Enhancement Proposal: Support for Nested App Creation with `startapp` Command in Django

11 views
Skip to first unread message

Django

unread,
Jan 19, 2025, 12:50:09 AM1/19/25
to django-...@googlegroups.com
#36113: Enhancement Proposal: Support for Nested App Creation with `startapp`
Command in Django
-------------------------------------+-------------------------------------
Reporter: JK | Type:
| Cleanup/optimization
Status: new | Component: Core
| (Management commands)
Version: | Severity: Normal
Keywords: core, command, | Triage Stage:
startapp, optimization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
**Summary:**

Django's startapp command currently creates a new app at the root level of
the project. Developers often adopt different project structures, and many
prefer organizing apps within subdirectories for better modularity and
clarity. A common structure might look like this:

{{{

|-- ./
|-- ./apps/<app name>
|-- ./apps/<app name>/apis/
|-- ./apps/dashboard/<app name>
|-- ./manage.py
}}}


To achieve this structure, developers currently need to:
1. Run `python manage.py startapp <app-name>`.
2. Manually move the generated app into the desired directory.
3. Update the apps.py configuration to reflect the new structure.

This process is tedious, error-prone, and does not contribute to creating
a "structured" project, particularly for first-time users.

**Proposed Enhancement:**

Enhance the startapp command to support nested app creation directly by
specifying the full path.
''Proposed Comand:''

For Linux / Mac
{{{
python manage.py startapp apps/dashboard/user
}}}

(or for Windows with a `\` instead of `/` as we expect)


''Proposed Changes:''
This command should:

- Automatically create the nested directory structure
`apps/dashboard/user`. * '[Clarification1]''
- Populate `apps/dashboard/user/apps.py` with the correct configuration
for `apps.dashboard.user`. using the classname `AppsDashboardUserConfig`
and name as `apps.dashboard.user`
{{{
from django.apps import AppConfig


class AppsDashboardUserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.dashboard.user'

}}}
- Provide a log message or output suggesting the exact string to add to
INSTALLED_APPS, e.g.,:
{{{
$ user@host: proj % django-admin startapp user apps/dashboard/user
App added to following directory : `apps.dashboard.user`
To integrate this app with your project, please add the following line in
your `settings.INSTALLED_APPS`.
"""
INSTALLED_APPS = [
...,
'apps.dashboard.user.apps.AppsDashboardUserConfig',
...,
]
"""

$ user@host: proj %
}}}

**Benefits:**

- Simplifies app creation for projects with nested or modular structures.
- Reduces manual steps and the risk of configuration errors.
- Enhances the developer experience, particularly for newcomers to Django.
- Keeping developer actions `DRY` and productive with minimum commands.

**Compatibility:**

The proposed change should maintain backward compatibility, allowing the
current behavior (creating apps in the root directory) to remain unchanged
when the provided path does not include subdirectories.

----
**Clarifications**
''[Clarification1]'': Django currently requires directories to be created
manually. Respecting this, the proposal suggests creating the directory
(if the user has permission). For projects requiring structured apps, this
enhancement reduces repetitive bugs and increases efficiency.

----
**A Note from Reporter:**
I am working with django for last 7 years, introducing the same from
startups to saas, - and would like to add such a contribution from my end,
if this can be assigned to me. Even else, the feature expects to be a
simple and wish to find as a part of django.

Thank You!
--
Ticket URL: <https://code.djangoproject.com/ticket/36113>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 20, 2025, 2:33:59 AM1/20/25
to django-...@googlegroups.com
#36113: Enhancement Proposal: Support for Nested App Creation with `startapp`
Command in Django
-------------------------------------+-------------------------------------
Reporter: Jerin Kachirackal | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Management | Version:
commands) |
Severity: Normal | Resolution: duplicate
Keywords: core, command, | Triage Stage:
startapp, optimization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => duplicate
* status: new => closed

Comment:

Hi Jerin, I believe this is roughly the same ask as in #18296
Notice that [https://docs.djangoproject.com/en/5.1/ref/django-
admin/#startapp you can specify a directory] when running `startapp`,
however that directory must already exist.
--
Ticket URL: <https://code.djangoproject.com/ticket/36113#comment:1>

Django

unread,
Jan 20, 2025, 4:28:01 AM1/20/25
to django-...@googlegroups.com
#36113: Enhancement Proposal: Support for Nested App Creation with `startapp`
Command in Django
-------------------------------------+-------------------------------------
Reporter: Jerin Kachirackal | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Management | Version:
commands) |
Severity: Normal | Resolution: duplicate
Keywords: core, command, | Triage Stage:
startapp, optimization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jerin Kachirackal):

I had gone through for the duplicates earlier. And I believe it's an
enhancement from that point. Not the duplicate.

Reasons are:
1. Manual adjustment of apps.py
2. Manual creation of directory.
3. Guidance of next step can be added.

Though these are not frequently used, but these really compete with manual
effort. It's an enhancement from what django is, and a generic form
compared to other closed issues.

Requesting for a re review if possible. Thank You.
--
Ticket URL: <https://code.djangoproject.com/ticket/36113#comment:2>

Django

unread,
Jan 20, 2025, 5:56:43 AM1/20/25
to django-...@googlegroups.com
#36113: Enhancement Proposal: Support for Nested App Creation with `startapp`
Command in Django
-------------------------------------+-------------------------------------
Reporter: Jerin Kachirackal | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Management | Version:
commands) |
Severity: Normal | Resolution: duplicate
Keywords: core, command, | Triage Stage:
startapp, optimization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce):

> Manual adjustments of apps.py

See #30618, but I also feel we can discuss this with #18296

> Manual creation of directory.

See #18296

> Guidance of next step can be added.

See #34976, I like you suggestion and will comment on the ticket
--
Ticket URL: <https://code.djangoproject.com/ticket/36113#comment:3>

Django

unread,
Jan 20, 2025, 7:53:03 AM1/20/25
to django-...@googlegroups.com
#36113: Enhancement Proposal: Support for Nested App Creation with `startapp`
Command in Django
-------------------------------------+-------------------------------------
Reporter: Jerin Kachirackal | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Core (Management | Version:
commands) |
Severity: Normal | Resolution: duplicate
Keywords: core, command, | Triage Stage:
startapp, optimization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jerin Kachirackal):

Thanks @Sarah Boyce.. <3
--
Ticket URL: <https://code.djangoproject.com/ticket/36113#comment:4>
Reply all
Reply to author
Forward
0 new messages