Django project with core code stored in an app with the same name
Django project with core code stored in an app with the same name
When creating a Django project (e.g. myapp
), the framework also creates a subdirectory/python package with the same name as the project to hold settings.py
, urls.py
and wsgi.py
:
myapp
settings.py
urls.py
wsgi.py
─ myapp
└─ myapp
├─ __init__.py
├─ settings.py
├─ urls.py
└─ wsgi.py
Although I then add a number of apps, I almost always have some core functionality that belongs to the project itself.
Is there any reason why I should not add the core functionality to the myapp
package alongside settings.py
and wsgi.py
and include this in settings.INSTALLED_APPS
? E.g.:
myapp
settings.py
wsgi.py
settings.INSTALLED_APPS
─ myapp
├─ app1
├─ app2
└─ myapp
├─ __init__.py
├─ models.py
├─ settings.py
├─ templates
| └─ homepage.html
├─ urls.py
├─ views.py
└─ wsgi.py
I've seen other people create a core
app instead to hold the 'core' code that is specific to the project, is this necessary?
core
myapp
myapp.firstapp
myapp.secondapp
1 Answer
1
I was just reading the Django docs for INSTALLED_APPS and I saw a link to "Learn more about application configurations" that answers my question:
There’s no restriction that a project package can’t also be considered an application and have models, etc. (which would require adding it to INSTALLED_APPS).
See: https://docs.djangoproject.com/en/2.0/ref/applications/#projects-and-applications
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I think you can do it either way, it is in my opinion matter of taste. You could also place all of your apps as subdirectories of the subdirectory
myapp
, having for examplemyapp.firstapp
,myapp.secondapp
. Depending on the complexity of the project you should look for the best way to group your code.– cezar
Jul 31 '17 at 15:49