Jun 14, 2017

How to Deploy a Django Application on Heroku?

Vladimir Kalyuzhny

1. Getting started on Heroku

First thing you need to do is to create an account. Heroku offers four pricing plans: Free, Hobby, Standard, Performance. In this tutorial we are going to use the Free-plan. It’s necessary to remember that this plan has certain limitations you need to peruse with before you deploy django app to heroku.

Creating an account on Heroku

If you already have an account on Heroku, skip this step. To create an account you need to fill out a registration form by clicking on the link. It shouldn’t take you more than one minute neither bring any difficulties. The only thing I want to pay attention to is that don’t forget to choose Python at “Primary Development Language” line. After filling the form confirm your email and let’s get down to business.

Installing the Heroku CLI

We’ll need Heroku CLI. In this tutorial we will quite often use CLI to interact with Heroku.

After the installation process is finished, open console and enter the username and password of your account.


Creating Heroku App


Connecting PostgreSQL


2. Configuring django apps for heroku

For this article I wrote a simple Django application. First, we need to do some adjustments to our app before starting to deploy django to heroku.


requirements.txt is a file which contains a list of all necessary app packages. Create this file in the root folder with such content inside:



Procfile describes command need to be executed for app launch.



It is the file in which we specify Python version


Separating Django settings

We need to get three files with the following settings:

  • settings/ - basic configuration
  • settings/ - production configuration (this particular file will be used on Heroku)
  • settings/ - local configuration

Such separation of settings will become necessary when our app starts to grow. You will find link to the code of these files at the end of this article.

Setting up static files

For the correct display of static files we need to modify и


Database Configuration

In the previous step we’ve created PostgreSQL database. Let’s connect it to our app. Go to “Settings” and copy the entire DATABASE_URL contents.

After that, paste contents into settings/, you must end up with this:


Local launch

Preliminary configuration of our app is done. Before we start to push django on heroku, let’s check how our app is displayed locally. For this we have heroku local web command.


If no mistakes were returned and you don’t see any of them in the console, then everything went well and you can proceed to the next step.

3. Deploying django to heroku

Logging into Heroku account


We'll push code and heroku should deploy the app automatically.


Running migrations

Don’t forget to add --settings=heroku_blog.settings.production, because that’s how system understands that particular file with production-server settings has to be used.


Checking the result

After completing all the steps above we get ready-to-go app which can be found at


If you’re receiving errors while deploying an app, you can check what went wrong


4. Django Celery on Heroku

Redis installation on Heroku


Updating the requirements.txt file

Add two new packages:



Take REDIS_URL value from Settings and paste it to settings/ After that, the Celery settings should look like that:


For Celery file has to be created in which celery initialization will take place. More details on how to set up celery in Django you can find here Using Celery with Django.


Let’s add celery test-task. This task was taken from the documentation and what it simply does is it returns a sum of two numbers.


Updating Procfile

As we have seen before, Procfile contains commands that need to be executed if we want to launch an app. We need to launch celery at the moment of the app launch. To do this we need to update procfile by adding the string worker: celery worker -A heroku_blog -E -l info. As a result, procfile should look like that:


Deploying Сelery on Heroku



We’re all set! Now let’s double-check if we did all correctly:

Open console and run a command


In the next tab run log output, there should appear statement that the celery task was completed successfully.


That’s it. The app’s source code you can find here:

More thoughts