Deploy Your Django Application On Heroku
- Shivam Rohilla
- May 22, 2022
- 3 comments
- 2238 Views
<meta name="clckd" content="6301244fb7ed470eb1cd6b8c31d01ac4" />
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
Now add some scripts in your settings.py
# django_heroku Configuration
import django_heroku
# 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'
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/'
Now, open cmd and run these commands
Connect your project to your Heroku app
heroku git:clone -a project_name
Now Deploy your changes using git
git add .
git commit -am "make it better"
git push heroku master
Now, most important add the Procfile file without any extension and open your Procfile and add this file.
web: gunicorn project_name.wsgi
If you have any problem please contact me or comment.
Thank You
My social media links