How to Deploy Django Project to Heroku


I try to explain how to deploy your django project to heroku.

First i want to talk about heroku

What is Heroku.

Heroku is a cloud application platform. It means you can easly build and deploy your web applications to Heroku servers.

Heroku makes you focus to your application code. It figures out build, deploy and manage server for you.

Heroku support Ruby, Python, Node.js, Java languages.


Lets start to deployment.

Step 1 - Create a heroku account than login

First go to heroku homepage and create an account. (free)

Then install heroku to your computer.

 brew install heroku 

*for manuel download

Login to heroku after installation,

 heroku login
Enter your Heroku credentials.
Email: [email protected] Password (typing will be hidden):
Authentication successful.

Now you can start to use heroku commands.

Step 2 - Create a heroku project

Before deployment you need to create a project on heroku. It is easy run this command

 heroku create projectname 

* if you dont write a project name, heroku will create your project with random name.

Step 3 - Set your project settings for heroku enviroment

Heroku using postgress

You need to switch your database to postgress if you are using any different.

Add dj-database-url to your requirements.txt than update your

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

Step 4 - Serv your static files

To serving static files you can use whitenoise.

 pip install whitenoise
 pip freeze > requirement.txt 

add this lines on your

 # Static files (CSS, JavaScript, Images)
  STATICFILES_STORAGE = ‘whitenoise.django.GzipManifestStaticFilesStorage' 

update your

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

When you deploy your project to collectstatic will run automatically.

Step 5 - Deploy your project

Everything is done, now we can deploy the django project to heroku.

 git push heroku master 

After deployment, open your project and see it on browser

 heroku open 



heroku home -
about heroku -
deployment -
serv static files -
Django Python Web Server 04-08-15