Step by Step guide to deploy Django Web App on Heroku

Posted 3 years, 7 months ago
Views 544
2 min read
0 reactions


  1. Signup on Heroku 

  2. Install git 

  3. Install Heroku CLI (Command Line Interface)

  4. Open Terminal and navigate into your project 

  5. Install “gunicorn” package by using the command pip install gunicorn 

  6. Install django heroku package by running the command pip install django-heroku

  7. Go to file in your project and add the following lines
          import django_heroku (add this after import.os line)
    (Scroll down to the bottom of page and add this line)

  8. Now go back to your terminal and check the list of all packages used in your project using the command pip freeze 

  9. Creating requirements.txt file
     Use this command pip freeze > requirements.txt to automatically create requirements.txt file in your project       

  10. Create a “git ignore” file in your project manually and copy the code from this link. File name should be as .git ignore

  11. Create a file with the name Procfile in the root directory of your project. Open the Procfile and write the following line.

           web : gunicorn projectname.wsgi

          (( Note: project name should be same as the name of your root directory where your file is located  ))

      Steps to push your code(project) into Heroku
      a.  git init

      b.  git add . 
      c.  git status 
      d.  git commit -m “First Commit” 
      e.  heroku create
appname (give your own appname)
      f.   heroku open  command is used to open your app in the browser 
      g.  git push heroku master command is used to push code into heroku

  1. Go to file in your project and then add your app domain name in ALLOWED HOSTS
             ALLOWED HOSTS = [‘your app domain name’]

  2.  Generate a new SECRET KEY which can be used for production. After generating new SECRET KEY update your environment variables file.

  3. Next go back to the terminal and run the following commands
            heroku config:set SECRET_KEY=”newgeneratedsecretkeyvalue”
            heroku config:set DEBUG_VALUE=”TRUE”

  4. Now update the file which is in your project directory and change the secret_key line to
            SECRET_KEY = os.environ.get(‘SECRET_KEY“)

  5. Commit the changes every time you make changes to the code

  • git add -A

  • git status 

  • git commit -m “Updated Commit”

  • git push heroku master

  • heroku open


Creating Postgresql Database: Heroku recommends to use Postgresql Database

  1. Heroku by default creates a postgres database when you create a heroku app.
    If its not created then run the following command
           heroku addons:create heroku-postgresql:hobby-dev

  2. After creating database you need to make migration now using the below command
           heroku run python migrate

  3. Create Super User for your new database by using the following command
           heroku run python create superuser 

  4. After creating superuser run the below command
           heroku open

  5. Now the app should open in your browser. Check the entire functionality of your app and then finally change the DEBUG value in file in your project.

                   DEBUG = (os.environ.get(‘DEBUG_VALUE’ == ‘TRUE’)) and then finally commit the changes like how we did in Step 17 and now your web app is                             deployed on Heroku.

Hope this article helps!

0 reactions


Posted 3 years, 7 months ago

Thanks. Excellent article.

Joined on July 30, 2020

Latest Videos