contact@digitalnotebooks.co
Stay Organized, Stay Inspired. Let's Write.

Car Listing: Deployment using Heroku Part 19B

Back To All Notes
  • Notebook: Django Project: Car Listing
  • Speaker:
  • Date Created: July 25, 2024, 11:14 p.m.
  • Owner: Rosilie

1. This is the SECOND PART in the Django deployment in Heroku.

2. The next thing we need to do is use the GIT command to 

$ git init
$ git add -A
$ git commit -m "started deployment"

3. Issue the HEROKU command,

$ heroku create

You have to go back to your browser and in the HEROKU PAGE, ADD A PAYMENT method since HEROKU does NOT  provide a free account.

You have subscribed using the ECO DYNOS PLAN  for personal projects. If this is not the case anymore, you can upgrade to HIGHER DYNOS PLAN.

After payment, we issued the command again and we get this:

CRYPTIC-CHAMBER-84584 is the random app name if heroku create code has no app-name.

**UPDATED: You recreated your app when you destroyed CRYPTIC-CHAMBER-84584  , this is your new random app name

4. Go back to the Gitbash terminal, and issue:

$ pip install dj-database-url

5. Update the SETTINGS.PY as

Next, comment out or delete the section below in the SETTINGS.PY:

After removing the dtabase block that was used in our localhost, we add this new line:

Syntax:

DATABASES = {'default':dj_database_url.config(default='postgres://user:password@localhost/dbname') }

Using the  DATABASES line, change it to your own database credentials. Use the details of your commented DATABASES BLOCK to replace the vaule of USER as POSTGRES, PASSWORD='yOUR DB PASSWORD', DBNAME as CARZONE_DB

6. Replace DEBUG=TRUE to DEBUG=FALSE during deployment or production.

FROM:

TO:

7. Next install, install the new package WHITENOISE

$ pip install whitenoise

8. Update SETTINGS.PY for WHITENOISE PACKAGE CONFIGURATION.

9. We need to update our Github repository. We issue the commands "GIT ADD -A", "GIT COMMIT -M "COMMENT"" but we CANNOT PUSH THIS TO GITHUB. We should however push this to GITHUB HEROKU. So we issue the command:

TAKE NOTE THAT ONCE YOU CREATE AN APP WITH HEROKU, ALL GIT COMMANDS ARE UPDATING THE HEROKU SERVER AND NOT THE GITHUB SERVER.

The tutorial uses GIT PUSH HEROKU MASTER, but this gives you an error. You have been using MAIN in your GITHUB REPOSITORIES. So with Heroku, we will use MAIN as well.

10. You encountered an error message that is similar to the tutorial  (tutorial uses Python 3.8.2 for Stack Heroku 18. Your error message is the same but for Python 3.9;9 Stack Heroku 22.

To correct this, update your RUNTIME.TXT and make Python to small letters.

FROM:

TO:

Update your REQUIREMENTS.TXT to make sure that you have the newly installed packages added (DJ_DJANGO_URL,WHITENOISE,GUNICORN,PSYCOPG2-BINARY)

$ pip freeze > requirements.txt
 

11.  Use GIT codes to push our changes to HEROKU SERVER. However, you will still encounter errors. 

This error was caused by the misspell you have on : We need to PUSH OUR CHANGES TO HEROKU SERVER AGAIN

12. Modifications made:

13. We encountered CONNECTION REFUSED ERROR,

We install the the HEROKU POSTGRES ADDON

heroku addons:create heroku-postgresql
 

14.  After the POSTGRES ADD-ON code was run we take the Database Info and its DATABASE_URL

The hidden block is your database password.

UPDATED: All the screenshots here are from the first app that was causing the error.

We redo our deployment by creating a new one from heroku CLI.

1. Create a new heroku app (this can be done using the browser too):

2. We need to have a HEROKU ADD-ON: POSTGRES, Since we had deleted our first app, heroku by default it pointing to this, so we issued explicitly the app's name,

3. To see the creation of his new add-on, we issue:

4. Now, we need to update our SETTINGS.PY, so that it has the DATABASES credential:

The hidden block is your database password.

5. You need to push your files/folder to HEROKU MAIN, we issue the command 'GIT PUSH HEROKU MAIN' but this is causing as an error because of the destroyed app. 

GIT REMOTE REMOVE HEROKU (to remove the remote link to our old app)

HEROKU GIT: REMOTE -A LIT-CLIFFS-98316 ( to connect to our new app)

6. UNFORTUNATELY, WE STOPPED BECAUSE HEROKU CANT SEEM TO IGNORE ALL MISSING BOOTSTRAP FILES. I tried to copy the the missing files from the Bootstrap website. but the error messages persist. We will work on deploying to Heroku again in the future.

UPDATE: Almost a week since my lat HEROKU SERVER PUSH, I ran my server again and get this message:

I used AI Copilot  to give me solutions and gave this:

Instead of writing an empty file of bootstrap-select.js.map, I searched for the file and copied it to CARZONE\STATIC\JS and push my changes again. Luckily, I get my migrations to run! Yahoo!

 



No PDF file attached.

Notebook
Notebook Details
Title: Django Project: Car Listing
Category: Udemy Django Course