diving deeper into django I came across the challenge to handle code which is not specific to 1 app but is shared/used by multiple apps.
I would not(!) like to store it as part of an app (to avoid app dependencies) but to have it in a specific place.
currently my best practice is to create a django app "shared" in which I place this code/functionality
so my project structure looks similar to this:
mysite/
manage.py
mysite/
...
shared
...
app1
...
app2
...
app3
...
...
is there a "django best parctice" or a more practical way how to handle this?
Django's features ensure you can link multiple related project apps, create apps that accept and store user information, and trigger actions, such as sending emails.
Django comes with six built-in apps that we can examine.
A project refers to the entire application and all its parts. An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification.
The order of INSTALLED_APPS is significant! Django applies the following algorithm for discovering translations: The directories listed in LOCALE_PATHS have the highest precedence, with the ones appearing first having higher precedence than the ones appearing later.
I usually do exact same thing what you are doing. Not sure if that is best practice however I've seen other people using the same approach. I like it because:
shared
/core
/etc app becomes useful in other projects, you can package it as reusable app which can be installed via pip
in other projectsThe only note about packaging it as a reusable lib is that I would recommend to rename it to something other then shared
. The reasons is that when you package it in PyPI lets say as my_django_utils
, then you will have to change all your imports in all the projects. If you come up with a generic name now, then you can easily package it in the future without needing to change all your imports...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With