Search code examples
djangoproject-structure

Use cases for new Django 1.4 project structure?


I guess this is sort of a followup question to Where should i create django apps in django 1.4? The final answer there seemed to be "nobody knows why Django changed the project structure" -- which seems a bit unsatisfactory.

We are starting up a new Django project, and currently we are following the basic structure outlined at http://www.deploydjango.com/django_project_structure/index.html:

├── project
│   ├── apps
│   │   ├── app1
│   │   └── app2
│   ├── libs
│   │   ├── lib1
│   │   └── lib2
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

But I think we also are anticipating a multi-developer environment comprising largely independent applications with common project-level components, so it seems cleaner to me to separate out the project and app paths.

├── project
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── apps
│   ├── app1
│   └── app2
├── libs
│   ├── lib1
│   └── lib2
└── manage.py

It's hard to come up with any specific, non-stylistic rationale for this, though. (I've mostly worked only with single-app projects before now, so I may be missing something here.)

Mainly, I'm motivated by the fact that Django 1.4 seems to be moving in the latter direction. I assume there is some rationale or expected use case that motivated this change, but I've only seen speculation on what it might be.

Questions:

  1. What was the motivation for the 1.4 project structure change?
  2. Are there use cases where having apps inside/outside of the project makes a non-trivial impact?

Solution

    1. It's much easier to extract an app from a project because there are no more imports like this:

      from projectname.appname.models import MyModel
      

      instead you import them the same way you would import apps which are installed via a python package

    2. if you use i18n then this could make an impact because makemessages searches for translation strings in the current directory. a good way to translate apps and the project using a single .po file is to create the locale folder outside the project dir

      ├── project
      │   ├── settings.py
      │   ├── urls.py
      │   └── wsgi.py
      ├── app1
      ├── app2
      ├── locale
      │   ├── en
      │   └── de
      └── manage.py