How to publish Django app on Heroku

  • The Procfile
Create a file named Procfile in the project root with the following content:
web: gunicorn reconstruct.wsgi --log-file -
  • The Requirement File (super important)
The requirements.txt
If you are using a virtualenv and pip you can simply run:
pip freeze > requirements.txt
Django==1.9.8 dj-database-url==0.3.0 dj-static==0.0.6 gunicorn==19.6.0 Unipath==1.0 python-decouple==3 Pillow==3.3.0 Markdown==2.6.6 bleach==1.4.3 psycopg2==2.6.1 whitenoise==3.2
  • The runtime.txt
Create a file named runtime.txt in the project root, and put the specific Python version your project use:
  • Set Up The Static Assets
Configure the STATIC-related parameters on
# Static files (CSS, JavaScript, Images)
STATIC_URL = ‘/static/’
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + [‘static’]))
  • Install the Whitenoise, and don’t forget to update the requirements.txt:
pip install whitenoise
  • Add the Whitenoise to your Django application in the file:
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)
  • Update the

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

  • Add config variable to disable static config variable
heroku config:set DISABLE_COLLECTSTATIC=1

Link :

Link :

Setting up Database and Admin and project

  • run the command python migrate
  • cmd: heroku addons:create heroku-postgresql:hobby-dev — app deploytrials
  • add this code :
import dj_database_url
db_from_env = dj_database_url.config()
  • heroku run bash — app deploytrials
  • migrate>> makemigrations>>createsuperuser

Creating New Project Using VS Template

  • Create New Django Project
  • Install virtualenv from VS console
  • python startapp webapp
  • Include webapp in the project in visual studio
  • Add webapp in installed projects
  • <Database migration >
  • add this in URL file of main project url(r’’,include(‘webapp.urls’)),
  • Create a in the webapp folder and add the following
  • add the following code in the in the webapp folder ()
  • add the following code in the
  • weapp └───templates └───webapp and add home.html


Now porting the same app on heroku

Like what you read? Give Harshit Yadav a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.