Deploy Django App to Heroku

Youtube: https://www.youtube.com/watch?v=V2rWvStauak

Github: https://github.com/akjasim/codeband-django-heroku

Usage

  1. If you don't have git installed, follow this Tutorial and come back here.

  2. Make a copy of your project or use a seperate git branch.

  3. Make sure your virtual environment is activated.

  4. Add your dependencies to requirements.txt by typing in the terminal,

$ pip freeze > requirements.txt

     5.  Add this in settings.py

code:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

     6. Make a Heroku account

https://signup.heroku.com/

     7. Download Heroku CLI

https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli

     8. Configure Django Heroku

https://devcenter.heroku.com/articles/django-app-configuration

making of Procfile

     9. In your terminal, type in

$ git init

$ git add .

$ git commit -m "first commit"

 

$ heroku login

$ heroku create app_name

$ git push heroku main

$ heroku open

 

$ heroku run python manage.py migrate

$ heroku run python manage.py createsuperuser

$ heroku open

options:

$ heroku run python manage.py syncdb

$ heroku run python manage.py migrate

$ heroku open

 

** PS: if Heroku isn't recognized as a command, please close your terminal and editor and then re-open it.

  •  DEBUG = False in settings.py

  •  ALLOWED_HOSTS = ['your_app_name.herokuapp.com', 'localhost', '127.0.0.1'] in settings.py

Note:

  • If you make edits, then just type in the terminal,

git add .

git commit -m "edit"

git push heroku main

 

 


 

Errors that may cames:

 

1. While installing the django-heroku

for django-heroku install:

$ sudo apt install libpq-dev

$ pip install django-heroku

 

2. not recognized of python in heroku and solving by making the runtime,txt files where it contains text as “python-3.8.10”.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3. Make an Procfile first letter capital and make it in root directory of quiz/ (i.e quiz project bhitra)

 

 

 

 

 

DEPLOY OF PROJECT:

 

If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login

Create a new Git repository

Initialize a git repository in a new or existing directory

$ cd my-project/

$ git init

$ heroku git:remote -a nabinsociallink

Deploy your application

Commit your code to the repository and deploy it to Heroku using Git.

$ git add .

$ git commit -am "make it better"

$ git push heroku master

 

You can now change your main deploy branch from "master" to "main" for both manual and automatic deploys, please follow the instructions here.

 

 

Existing Git repository

For existing repositories, simply add the heroku remote

$ heroku git:remote -a nabinsociallink