What I’d like to do: enable django-webhook only if the user has installed the package (via extras or whatever)
It looks like specifying an application that doesn’t exist / isn’t installed causes an ImportError. Can this be caught? Can I do things like enable and disable menus in the frontend based on what’s installed?
Are you creating a reusable django package or an end project to be hosted somewhere?
Ok, the installed apps setting is global across users of the project. If you were to remove it for a single user then it would affect every user.
Yeah I get that, I’m thinking about the case where it’s hosted by a single user for a single user.
If that user doesn’t pip install the package, they don’t get that menu item - but this kind of dynamic loading doesn’t seem possible.
It probably is possible given settings.py is just a python file and INSTALLED_APPS is just a list. There is nothing special about either of them.
So you could do:
INSTALLED_APPS = [...]
try:
import django_webhook
INSTALLED_APPS += ['django_webhook']
except ImportError
pass
or similar.
1 Like