Post

How to publish Django app on Heroku

How to publish Django app on Heroku

How to publish Django app on Heroku

  • The Procfile

  • The Requirement File (super important)

  • The runtime.txt

  • Set Up The Static Assets

  • Install theWhitenoise, and don’t forget to update therequirements.txt:

  • Add theWhitenoiseto your Django application in thewsgi.pyfile:

  • Update the settings.py

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

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

Link :https://simpleisbetterthancomplex.com/tutorial/2016/08/09/how-to-deploy-django-applications-on-heroku.html

Link :https://github.com/heroku/heroku-django-template

Setting up Database and Admin and project

  • run the command python manage.py migrate
  • cmd: heroku addons:create heroku-postgresql:hobby-dev — app deploytrials
  • add this code :
1
import dj_database_urldb_from_env = dj_database_url.config()DATABASES['default'].update(db_from_env)
  • heroku run bash — app deploytrials
  • migrate» makemigrations»createsuperuser

Creating New Project Using VS Template

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

Vola

Now porting the same app on heroku

Reference

This post is licensed under CC BY 4.0 by the author.