DEV Community

Cover image for Deploy Django project on Heroku
Shivam Rohilla
Shivam Rohilla

Posted on

Deploy Django project on Heroku

Hello Devs, Today I'm going to tell you how can you upload your Django project on Heroku in just simple steps..

First of all, install some modules :-

pip install django-heroku   
pip install gunicorn
pip install whitenoise 
Enter fullscreen mode Exit fullscreen mode

Now add some scripts in your settings.py

django_heroku Configuration

import django_heroku
Enter fullscreen mode Exit fullscreen mode

Whitenoise Configuration

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

#This above is very imp for the condition when debug=True, so please paste this file here

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
Enter fullscreen mode Exit fullscreen mode

Static and Media Settings

MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
MEDIA_URL = '/media/'
Enter fullscreen mode Exit fullscreen mode

Now, open cmd and run these commands
Connect your project to your heroku app

heroku git:clone -a project_name
Enter fullscreen mode Exit fullscreen mode

Now Deploy your changes using git

git add .
git commit -am "make it better"
git push heroku master
Enter fullscreen mode Exit fullscreen mode

Now most important add Procfile file without any extension and open your procfile and add this file.

web: gunicorn project_name.wsgi

Enter fullscreen mode Exit fullscreen mode

If you have any problem please contact me or comment.
Thank You

Top comments (0)