CodeChit

Programming, Django and Frameworks

Menu
  • Programming
  • Python
  • Django
  • Blogging
    • wordpress
    • Blogger
  • DMCA/PRIVACY
  • Videos
Menu
Django Deployment To Heroku

Python Django Website Deployment To Heroku (GUIDE)

Posted on May 19, 2020June 4, 2020 by PK Karn

Hello Coders, I hope you all have completed your first website project in Python Django Framework. Now, It’s time to deploy that website on server like Heroku. After Deployment, you any one can easily see your Django website online live.

Django Deployment To Heroku

Deploying A Django website on Heroku server is much easier as compare any other platform. All you need to just pay some attention before deploying your website. Therefore, In this article I’m gonna give Full Guide from scratch that How To Deploy Your Django website Freely on Heroku Server.

So, Please read full article carefully and don’t miss any steps. Because If you will miss any steps then you might have to face some issue in deployment. Let’s start our Heroku deployment tutorial…

Table Of Contents show
1 Steps To Deploy Django Website On Heroku:
1.1 Before Deployment Process:
1.2 Second Phase: Deploying Process On Heroku
1.3 You may also like

Steps To Deploy Django Website On Heroku:

Basically, I’ve divided entire deployment process into 2 different phases. The first phase going to take place “Before Deployment” and Second Phase will be about “Deployment Process“.

Before Deployment Process:

Let’s see that what we need to configure and manage before deploying our website to heroku server.

1). First Create a File called “Procfile” without an extension inside your Root directory of your project and then write inside following context inside your file

web: gunicorn root_folder.wsgi

Don’t Forger to change here “root_folder” with your Project name and then just save it.

Deployment Of Django Website

2). If you have any css or static file then don’t forget to mention and add that into settings.py file. So, that It could be recognize by your Main app.

In “Settings.py”, Add:
STATIC_ROOT = os.path.join(BASE_DIR,’static’)
Or (If any Errors), Then Add:
STATICFILES_DIRS = [ os.path.join(BASE_DIR,’static’) ]

3). Now Inside your terminal of main root directory of project type following command:

“python manage.py collectstatic”

Django To Heroku Deploy

4). Now You need to enter following command inside your terminal to add requirements file.

“pip freeze > requirements.txt”

Now Once you have done all above steps, then let’s move to second phase of our deployment process.

Second Phase: Deploying Process On Heroku

Now Before heading towards steps of Deployment Django to Heroku, First you need to install two packages called “whitenoise” and “gunicorn“. You can install both packages using command:

“pip install whitenoise”
“pip install gunicorn”

Now, Let’s head towards our deployment steps of django website to heroku:

1). In “Settings.py” file, Add In MIDDLEWARE section at second position:

'whitenoise.middleware.WhiteNoiseMiddleware',
Heroku Middleware

2). Now You Need To SignUp and Create an Account on Heroku.

3). Once you have registered then sign in an Create APP e.g:

Heroku Create Django app

4). Now In Settings.py File add “yourappname.herokuapp.com” inside ALLOWED_HOSTS

Allowed Host in Django Website

5). Now In terminal of Project Root Directory type following command.

“heroku login”

Deploying Free On Heroku

6. Once you’ve logged in then type following commands one by one.

>>git init
>>git add .
>>heroku git:remote -a appname
>>git commit -m “first commit”
>>git push heroku master

Once you’ve completed all above process then you would get message on terminal something like this:

Deploy Free Django Website To Live

7. Congratulation, Now Your Django Website is Live

Website Built With Python Djnago

You May Also Like: How To Improve You Coding Skills(Tips)

If you would like to make changes then you can easily do that through given commands:

Make Sure You Made all change before applying following commands.

>>git add .
>>git commit -m “commit”
[Make sure change git befor push]
>>”git push heroku master” or “git push -u origin master”

So, I hope you all would like this article. If yes then please don’t forget to share this article with your friends. You can also follow our blog via email to get future updates regarding career development and programming.

  • Share on Facebook
  • Share on Twitter
  • Share on Pinterest

You may also like

  • Django + Github Auto deployment to Heroku
    Django
    Django + Github Auto deployment to Heroku
    Hello coders, In this article, I'll show you How to deploy your Django web app t...
  • Authentication with django-allauth in Django Apps
    Django
    Authentication with django-allauth in Django Apps
    Hi coders, In this article, I will show you how to setup Authentication with hel...
  • How to Install And Use VueX in VueJS 3 (GUIDE)
    Framework
    How to Install And Use VueX in VueJS 3 (GUIDE)
    Hello coders, In this article I'm going to show you that how you can install Vue...
  • VueJs 3 Basic Concepts – Getting started with Vue (GUIDE)
    Framework
    VueJs 3 Basic Concepts – Getting started with Vue (GUIDE)
    Hi coders, It's a brief VueJS 3 Guide for beginners. And I'm going to explain ba...
  • Arrow Function in JavaScript ES6 (GUIDE)
    JavaScript
    Arrow Function in JavaScript ES6 (GUIDE)
    Arrow function in Javascript is one of the most useful feature that was introduc...
  • Filter() method in Python
    Filter() method in Python
    The Filter() method is one of the most useful and inbuilt method in Python progr...

1 thought on “Python Django Website Deployment To Heroku (GUIDE)”

  1. Pingback: How To Add Bootstrap 4 with Django Crispy Forms - HK2LITE.COM

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to create and register the component in VueJS 3
  • How to Install And Use VueX in VueJS 3 (GUIDE)
  • How to setup Vue Router in VueJS 3 (GUIDE)
©2021 CodeChit | Design: Newspaperly WordPress Theme