Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Last active August 21, 2018 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoodnessEzeokafor/3f89df7b7848f76ad32ac367525e125a to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/3f89df7b7848f76ad32ac367525e125a to your computer and use it in GitHub Desktop.
Deploying Your Django App On Heroku

#Install The Following Packages Django==2.0.7 # django dj-database-url==0.5.0 # for your database whitenoise==4.0 # to manage your static files on heroku gunicorn==19.9.0 # to deploy your app on heroku django-heroku==0.3.1

#Include the following on your .gitignore file *.pyc *.pyo pycache/ db.sqlite3 notes.md !Note do not include your migrations

activate your virtual environment

$ source bin/activate - #ubuntu users

Create a Procfile file named 'Procfile'; add the following

web: gunicorn .wsgi --log-file - #Note should be the folder where wsgi is located

cd into your base directory then type the following:

  • $ heroku create
  • $ git status
  • $ git add .
  • $ git commit -m 'initial commit'
  • $ git push heroku master # to heroku
  • $ git push origin master # to you github repo # if you already have a github repo
  • $ pip freeze > requirements.txt # !important
  • $ git push heroku master
  • Add the following to your settings.py

    ''' At the beginning of settings.py ''' import dj_database_url # heroku import django_heroku # heroku

    edit your allowed_hosts

    ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'hack-jos.herokuapp.com'] # heroku

    Add this to your apps

    INSTALLED_APPS = [ .....# 'whitenoise.runserver_nostatic', # heroku, whitenoise python manage.py runserver --nostatic

    ]

    Add this to your MIDDLEWARE

    MIDDLEWARE = [ 'whitenoise.middleware.WhiteNoiseMiddleware', # heroku manageing static files ]

    Database

    DATABASES = { 'default' : { 'ENGINE':'django.db.backends.postgresql_psycopg2', 'NAME': 'DB_NAME', # name of your database 'USER':'DB_USER', # user you created when creating your database 'PASSWORD':'DB_PASS', # password 'HOST':'localhost',# host 'PORT':'5432' # port } } Note when deploying on Heroku you are gonna use postgres

    Add the following

  • STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  • # heroku
  • STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  • db_from_env = dj_database_url.config(conn_max_age=500) # heroku
  • DATABASES['default'].update(db_from_env) # heroku
  • django_heroku.settings(locals())
  • # for django Delete your db.sqlite3 file
  • python manage.py makemigrations
  • python manage.py migrate
  • python mange.py createsuperuser
  • heroku run python manage.py makemigrations
  • heroku run python manage.py migrate
  • heroku run python manage.py createsuperuser
  • @GoodnessEzeokafor
    Copy link
    Author

    Will Still Udate It

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment