DEV Community

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

Posted on

1

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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay