Deploy Django to HEROKU
This page explains how to deploy Django on HEROKU
HEROKU fully supports Python-based applications and this page explains the steps that any developer can follow and deploy their apps using a minimal configuration. Any Django project can be deployed in two ways:
- Using the CLI and a short sequence of commands
- Using HEROKU UI and connect the GitHub repository
Before trying to deploy a Django project, the codebase needs to be updated (settings and dependencies), in order to have a succesfull deploy.
Prepare Django for HEROKU
This section explains changes we need to apply on a Django project, as required by the HEROKU platform.
All mentioned changes are applied to this sample project, saved on GitHub: HEROKU & Django Starter
- add
django-heroku
module to the requirements.txt - add Procfile in the root of the project
- this file informs HEROKU where is the entry point in the Django APP
- edit the project settings to include the following snippet (at the end of the file):
import django_heroku
django_heroku.settings(locals())
With all the above edits completed, we can use the HEROKU CLI to deploy the app
Deploy on HEROKU via CLI
Once our account on HEROKU is created and we are authenticated, we can start a new deployment.
For this demonstration, the open-source sample will be used, and of course, the first step is to clone the source code:
👉 Step #1 - Clone/download the sources:
$ git clone https://github.com/app-generator/deploy-heroku-django.git
$ cd deploy-heroku-django
👉 Step #2 - Link the terminal with HEROKU account
$ heroku login
This will open a new browser window where we need to confirm the deployment.
👉 Step #3 - Push the sources into HEROKU cloud
$ git push heroku master
👉 Step #4 - Migrate the database on the remote deployment
$ heroku run python manage.py migrate
👉 Step #6 - Access the deployed app
$ heroku open
The product should be similar to the this one Django Material Kit:
Deploy using HEROKU UI
An alternative to the CLI deployment, we can trigger a deployment using the UI. Here are the steps:
👉 Step #1 - Access the dashboard
👉 Step #2 - Create a new APP
👉 Step #3 - Connect the GitHub repository
👉 Step #4 - Trigger a new deployment
👉 Step #5 - Checkout the progress
👉 Step #6 - Deployent is finished
👉 Step #7 - The application is LIVE
✅ Resources
- 👉 Access AppSeed and start your next project
- 👉 Deploy Projects on Aws, Azure and Digital Ocean via DeployPRO
- 👉 Create an amazing landing page with Simpllo, an open-source site builder
- 👉 Django App Generator - A 2nd generation App Builder