Get Started with Django on Scalingo


Before doing this tutorial you should have setup your environment:

Initialize your application

# Create your project
mkdir my-project
cd my-project

# Create a virtualenv
virtualenv venv
source venv/bin/activate

# Install Django toolbelt
pip install django-toolbelt

# Initialize Django project, this command will
# create a file and a my-app directory startproject my-app .

Define the how to start your application

You have to create a file named Procfile at the root of the project containing:

web: gunicorn my-app.wsgi --log-file -

By default, the platform is looking for the web process type to start. The previous command defines it and tells Gunicorn, the applicative HTTP server, to display logs on stdout to fit the 12-factor principles.

Python app recognition and dependencies definition.

The platform will understand that your app is a Python application if it contains a requirements.txt file at the root of the project. To create it, your have to run the following command:

pip freeze > requirements.txt

Create your application and databases on Scalingo

$ scalingo create my-app
  • Go on the dashboard of your application.
  • Select the Addons category
  • Choose the database you want to use


Nothing to do


By default, only the PostgreSQL driver is installed, you need to replace it by the MySQL driver.

pip uninstall psycopg2
pip install mysqlclient
pip freeze > requirement.txt

Application configuration

The configuration of the application has to be done through the environment variables, no credentials should be present statically in the code. It is usually a bad practice.

The configuration file in our example is located at my-app/

Ensure that the base directory of the application is defined

Add (if not already set) the following definition after the top comment header of the my-app/ file:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

Configure the Database access

Still in the my-app/, replace:

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),


import dj_database_url

  database_url = os.environ["DATABASE_URL"]
except KeyError:
  database_url = "file:///{}".format(os.path.join(BASE_DIR, 'db.sqlite3'))

DATABASES = { 'default': dj_database_url.config() }

This has no effect on the default behavior. If no DATABASE_URL has been set, the application will fallback on your development backend, sqlite3. However, we advise you to use the same database in development and in production to ensure bug free migrations.

Static file serving


STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

    os.path.join(BASE_DIR, 'static'),



from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

Cling is part of the dj_static module and is designed to serve static files.

Save your app with Git

Setup .gitignore

You don’t want to keep track of everything on your version control system. To prevent such files to be added to Git, create the file .gitignore at the root of your project with the following content:


Commit your application

git init
git add .
git commit -m "Init Django application"

Deploy your application

git remote add scalingo<app_name>.git
git push scalingo master

Access your application

Waiting for your application to boot...
<-- -->

mode_edit Suggest edits