Deploying Django Applications

Getting Started

Your app needs a top-level file with a global variable named application that refers to your Django WSGI application. The file should already exist in the Django project, although a copy of it needs to be in the root directory in order for Helion Stackato recognize it:

$ startproject dj14
$ cd dj14
$ cp dj14/

Typically, the file is just three lines of code:

import os
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Your project must also have a requirements.txt file containing at least the django project:

$ cat requirements.txt

Configuring a Database

  1. You must modify the DATABASES variable of your project's as below to detect the database service provisioned by stackato:

    import urlparse
    DATABASES = {}
    if 'DATABASE_URL' in os.environ:
            url = urlparse.urlparse(os.environ['DATABASE_URL'])
            DATABASES['default'] = {
                    'NAME': url.path[1:],
                    'USER': url.username,
                    'PASSWORD': url.password,
                    'HOST': url.hostname,
                    'PORT': url.port,
            if url.scheme == 'postgres':
                    DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
            elif url.scheme == 'mysql':
                    DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
            DATABASES['default'] = {
                    'ENGINE': 'django.db.backends.mysql',
                    'NAME': 'dev.db',
                    'USER': '',
                    'PASSWORD': '',
                    'HOST': '', # Set to empty string for localhost.
                    'PORT': '', # Set to empty string for default.

    See Using Configured Database Services for more information on connecting with database services.


In the future, this may be automatically written to (similar to and others)

  1. Add a new dependency to requirements.txt:

    $ echo 'mysql-python' >> requirements.txt

Initializing the Database

Run the syncdb command to initialize the database tables:

$ stackato run <appname> python syncdb

If you use a data migration library such as South, also run:

$ stackato run <appname> python migrate

Configuring Static Media

There are various ways to serve static files for a Django application. Option #1 is the most recommended for production deployments; option #3 is the simplest for non-production, development, or test deployments.

  1. Directly serve static files with uWSGI. See Serving static files with uWSGI for details. or:
  2. Use django.contrib.staticfiles, which is included by default in Django 1.3. Read the Django documentation to understand the steps involved:
  3. Set DEBUG=True in This is not recommended for production applications.

Configuring the Project Location

Your project's may not always reside at the root directory. Furthermore, you may want to extend sys.path to point to certain project sub-directories.

To persist such environment changes (across,,, and so on), add the following to manifest.yml:

  DJANGO_SETTINGS_MODULE: myproject.settings
  PYTHONPATH: myproject

This assumes that your Django project lives under the myproject/ sub-directory.