Contact US

Get Your Project Done by our experts

Deploy your django app on Heroku for free


Deploy your django app on Heroku

To host your django app, first you have to install few pakages as shown below:

pip install gunicorn

once gunicorn is installed, install the whitenoise dependency using the following command.

pip install whitenoise

Now, create a file with the name as "Procfile" and do not add any extension to it. Open the file and paste the below code:

web: gunicorn projectname.wsgi --log-file -

 For Example, our project name is blog. So the code in procfile will be as shown below :

web: gunicorn blog.wsgi --log-file -

Now, we need to add a requirements.txt file. All the required dependencies will be mentioned in that file for Heroku to know the requirements of our project. To create this file, just paste the following command in your gitbash/ command prompt.

pip freeze > requirements.txt

You can open the requirements.txt file and you will find all the requirements and dependencies required to run your django app.

Open the file and in the ALLOWED_HOSTS just add the domain name/appname which you have created in heroku. This will allow that domain to access our project. But your project will not run on the localhost now. To run it on the localhost, just add the localhost in the list as shown below.


For Example, our heroku appname is blogom, when you click the view app in heroku, it will open a new tab in the browser with the address Mention that domain name in th eallowed host list in the  :

ALLOWED_HOSTS = ['localhost','']

You can use either or you can just write "localhost" to run your django app on the localhost.

 Note: When deploying your django app, set the debug to false.

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

Add the whitenoisemiddleware after the SecurityMiddleware and before the SessionMiddleware as shown below:


When deploying to heroku, you will get an error that heroku can't get staticfiles. To remove that error, just create a folder in your main directory and name it staticfiles. Open your file and add the below code :

# Static files (CSS, JavaScript, Images)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles'#add this line here

STATIC_URL = '/static/'

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

And now our django app ready to deploy. Watch the above video for step by step demonstration.

Tags: How to Deploy django app on Heroku, Host django app on heroku, Deploy django app for free on Heroku

© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT