How to add a new Django application to a project¶
The recommended way of installing Django applications is to use a Divio Cloud addon - an application that has already been packaged for easy installation in our projects.
If an addon has not yet been created for the application you require, you have two options:
- Add the application to the project manually (described in this article).
- Create an addon (described in How to package a Django application as an addon).
Make the package available to the project¶
You can do this in one of two ways:
- Copy the application to the root of the Python directory, so it’s on the Python path.
- Add it to
requirements.in. See How to install Python dependencies in a project for details on how to do this.
Configure the project¶
Add the names of any required applications to the
Other key settings (such as
MIDDLEWARE_CLASSES) will already be defined in
settings, so don’t simply declare them (e.g.
[...]). If you do this, you will overwrite existing settings. Instead, use
Ordering of settings lists¶
The ordering of applications, middleware and other settings lists can matter, in which case you may need to make sure you add the item at the start, end or particular position in the list.
If for example your
DebugToolbarMiddleware should be directly after the
GZipMiddleware, you could do:
MIDDLEWARE_CLASSES.insert( MIDDLEWARE_CLASSES.index("django.middleware.gzip.GZipMiddleware") + 1, "debug_toolbar.middleware.DebugToolbarMiddleware" )
urls.py of the project in the usual way, to include the
urls.py of your application, for example:
urlpatterns = [ url(r'^polls/', include('polls.urls', namespace='polls')), ] + aldryn_addons.urls.patterns() + i18n_patterns( # add your own i18n patterns here *aldryn_addons.urls.i18n_patterns() # MUST be the last entry! )
Alternatively, add the URL configuration to be included via one of the
addon URLs settings, in your project’s
Migrate the database¶
If the application has migrations, you should test them locally. Run:
docker-compose run web python manage.py migrate