Skip to content

Revisiting the project root vs project_slug folder for creating apps #4031

@hnarayanan

Description

@hnarayanan

Description

This issue is in the vein of #1725 and #3803, and discussions elsewhere e.g. https://stackoverflow.com/questions/39838290/is-there-a-command-for-creating-an-app-using-cookiecutter-django

The basic question is where is the canonical place to create an app?

  • The most natural thing to do, ./manage.py startapp <app_name>, creates it at the root level which looks yucky.
  • Moving it manually and tinkering with apps.py aesthetically looks nice (except the LOCAL_APPS in settings) but seems to not work in edge cases. e.g., I use a lot of Django's lazy loading of ForeignKey models (using strings) to avoid circular imports. In this situation I'm now forced to say project_slug.app_name.ModelName which is not an allowed thing to do.

My proposal is that we consider (the inner, as in not project root) {{cookiecutter.project_slug}} folder the root folder you'd get if you did django-admin.py startproject project_slug, and possibly even call it src.

Then you'd have something like:

{{cookiecutter.project_slug}}
├── compose
├── docs
├── locale
├── requirements
└── src
    ├── manage.py
    ├── app1
    ├── app2
    ├── {{cookiecutter.project_slug}}
    │   ├── config
    │   │   └── settings
    │   ├── contrib
    │   │   └── sites
    │   │       └── migrations
    │   ├── static
    │   │   ├── css
    │   │   ├── fonts
    │   │   ├── images
    │   │   │   └── favicons
    │   │   ├── js
    │   │   └── sass
    │   ├── templates
    │   │   ├── account
    │   │   ├── pages
    │   │   └── users
    │   └── utils
    └── users
        ├── api
        ├── migrations
        └── tests

In the above, the users app is no longer special, and doesn't need to be imported as {{cookiecutter.project_slug}}.users in the settings file. The config folder is also moved, but is perhaps not even necessary as it might be more vanilla Django to simply have.

└── src
    ├── manage.py
    ├── app1
    ├── app2
    ├── {{cookiecutter.project_slug}}
    │   ├── settings

I am a fan of this project and I try to use it and get caught up on this specific aspect of where to create an app every time I try. I would be willing to implement these proposed changes as an experiment if others agree with the general thought process.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions