is the concept of dependencies available in Django apps too?
For example, let's say I'm building my own custom Django app "polls" that can be reused in any Django project.
so whenever you need to add it to a project, you will have to add
INSTALLED_APPS = [
...
'polls.apps.PollsConfig',
]
but let's also say, that this polls app depends on the Django REST Framework, so whenever you use it, you will have to add that as well
INSTALLED_APPS = [
...
'polls.apps.PollsConfig',
'rest_framework',
]
And how about if it depends on even way more apps, do I have to list them all again in the settings.py of each and every project?
Or, is there some way to add rest_framework as an installed app inside the apps.py of the polls app so that it's automatically installed whenever polls is installed on a project?
The pluggable apps cant override the host project's settings. We can add more checks and validations to the apps before the project run.
FYI: to validate the presence of the dependency package, we can make use of the ready(...)--(DOC) method of PollsConfig class as,
from django.contrib.admin.apps import AdminConfig
class PollsConfig(AdminConfig):
def ready(self):
try:
import rest_framework
except ImportError:
raise ValueError("Missing 'rest_framework' from 'INSTALLED_APPS'")