Optional Django Apps
标签:python, django, hacksA project of mine contains a number of third-party apps that are development
related and potentially not available on every machine the project will run
on. My general approach to dealing with these was to try and import the app in
my settings
module and if successful, add it to the INSTALLED_APPS
setting. However as the number of these apps grew it became a wart within the
settings module so I put together this snippet for managing them.
We first create a sequence of dictionaries, each containing information about
an installed app such as the module to try and import, an extra potential
condition for checking and then the sequences of names to add to
INSTALLED_APPS
, MIDDLEWARE_CLASSES
and TEMPLATE_CONTEXT_PROCESSORS
.
Let’s start with the settings for optionally including the apps django-
command-extensions,
django-debug-toolbar and
south.
Next we simply iterate through the sequence of optional apps and set them up.