Your app needs a top-level wsgi.py 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 Stackato recognize it:
$ django-admin.py startproject dj14
$ cd dj14
$ cp dj14/wsgi.py wsgi.py
Typically, the wsgi.py 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
django==1.4
mysql-python
You must modify the DATABASES variable of your project's settings.py 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'
else:
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.
}
Please see Using Configured Database Services for more information on connecting with database services.
Note
In future, this may be automatically written to local_settings.py (similar to ep.io and others)
Then add a new dependency to requirements.txt:
$ echo 'mysql-python' >> requirements.txt
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/test deployments.
Your project's settings.py 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 wsgi.py, settings.py, manage.py, etc.), add the following to stackato.yml:
env:
DJANGO_SETTINGS_MODULE: myproject.settings
PYTHONPATH: myproject
This assumes that your Django project lives under the myproject/ sub-directory.