How to add a new Django application to a project¶

Note

This article assumes you are already familiar with the steps involved. Fora full walk-through, see the Add new applications to the project section ofthe developer tutorial.

The recommended way of installing Django applications is to use a Divio Cloudaddon - an application that has already been packaged for easy installation inour projects.

If an addon has not yet been created for the application you require, you havetwo options:

Make the package available to the project¶

You can do this in one of two ways:

Configure the project¶

Configure settings¶

Add the names of any required applications to the INSTALLED_APPS.extend()method in settings.py.

Other key settings (such as MIDDLEWARE_CLASSES) will already be defined insettings, so don’t simply declare them (e.g. MIDDLEWARE_CLASSES =
[…]
). If you do this, you will overwrite existing settings. Instead, usefor example MIDDLEWARE_CLASSES.extend([…]).

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 orparticular position in the list.

If for example your DebugToolbarMiddleware should be directly after the GZipMiddleware, you could do:

  1. MIDDLEWARE_CLASSES.insert(
  2. MIDDLEWARE_CLASSES.index("django.middleware.gzip.GZipMiddleware") + 1,
  3. "debug_toolbar.middleware.DebugToolbarMiddleware"
  4. )

Configure URLs¶

Edit the urls.py of the project in the usual way, to include the urls.py of your application, for example:

  1. urlpatterns = [
  2. url(r'^polls/', include('polls.urls', namespace='polls')),
  3. ] + aldryn_addons.urls.patterns() + i18n_patterns(
  4. # add your own i18n patterns here
  5. *aldryn_addons.urls.i18n_patterns() # MUST be the last entry!
  6. )

Alternatively, add the URL configuration to be included via one of theaddon URLs settings, in your project’s settings.py.

Migrate the database¶

If the application has migrations, you should test them locally. Run:

  1. docker-compose run web python manage.py migrate

Deploy the project¶

Push your changes¶

  1. git add <changed or added files>
  2. git commit -m "<message describing what you did>"
  3. git push origin develop

Deploy the Test server¶

  1. divio project deploy test

原文: http://docs.divio.com/en/latest/how-to/add-application.html