This document contains information for Django programmers deploying their applications on cloudControl.
The python buildpack uses pip to manage dependencies. Specify your dependencies in a file called requirements.txt in the project root directory.
cloudControl uses a Procfile to know how to start your processes. This file specifies a web command that will be executed to start the server once the app is deployed. It optionally also specifies worker types that can be used to execute long running tasks.
The Procfile for a Django app using gunicorn as web server can look like this:
web: python manage.py run_gunicorn --config gunicorn_config.py -b 0.0.0.0:$PORT
manage: python manage.py
Use the run command to execute tasks like syncdb. This starts an interactive SSH-session.
cctrlapp APP_NAME/DEP_NAME run "python manage.py syncdb"To use a database, you should choose an Add-on from the Data Storage category. To get the credentials of your database, refer to the Add-on credentials article.
You can't use a local SMTP server, instead choose one of our email Add-ons.
Since there is no webserver , i.e. Apache or Nginx running inside the container to serve the static files. We recommend to usedj-static or whitenoise in combination with a WSGI server like Gunicorn. Another approach is using a CDN, e.g. Amazon S3 to serve static files for your application with django-storage. For further details, checkout the official package documentations.
The following code snippets showing how to use dj-static or whitenoise:
- Add the following line to the requirement.txt:
dj-static==0.0.6- Modify your settings.py:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'- Update your wsgi.py with the following line:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())Please make sure that your files getting served properly, by adding an empty dummy text file in the static folder of your repository, for testing purposes.
- Add the following line to the requirement.txt:
whitenoise==2.0.3- Modify your settings.py:
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'- Update your wsgi.py with the following line:
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)