advanced#Django#Heroku#Deployment
Deploying a Django App to Heroku
Learn how to deploy a Django app to Heroku, a popular cloud platform for building and deploying web applications.
Introduction to Heroku Deployment
Heroku is a popular cloud platform for building and deploying web applications. In this tutorial, we will explore how to deploy a Django app to Heroku.
Step 1: Create a Heroku Account
Create a Heroku account and install the Heroku CLI:
brew install heroku
Step 2: Initialize a Git Repository
Initialize a Git repository for your Django project:
git init
Step 3: Create a Heroku App
Create a new Heroku app using the Heroku CLI:
heroku create
Step 4: Configure the Django App for Heroku
Configure the Django app to use Heroku's PostgreSQL database:
import os
database = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DATABASE_NAME'),
'USER': os.environ.get('DATABASE_USER'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'HOST': os.environ.get('DATABASE_HOST'),
'PORT': os.environ.get('DATABASE_PORT'),
}
Step 5: Deploy the App to Heroku
Deploy the app to Heroku using the Heroku CLI:
git add .
git commit -m 'Initial commit'
heroku git:remote -a <app-name>
git push heroku master
Step 6: Run Migrations and Collect Static Files
Run migrations and collect static files on the Heroku server:
heroku run python manage.py migrate
heroku run python manage.py collectstatic