Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Boilerplate template for Django projects to be deployed on Heroku

Notifications You must be signed in to change notification settings

ArjunS07/heroku-django-boilerplate

Repository files navigation

Heroku Django boilerplate

This git repository is meant to be a bare-bones template for creating Django apps that can quickly be deployed to Heroku.

Template information

Packages

This template uses pipenv and contains the following packages:

  • django
  • gunicorn
  • dj-database-url
  • psycopg2-binary
  • whitenoise
  • django-environ

Settings configuration

  • The secret key is ready to be configured from a local .env file and Heroku variables
  • dj-database-url is used for configuring the database URL
  • Static files are configured. urls.py also contains a static URL

Install instructions

Prerequisites

You need to have the following installed on your system:

  • Python
  • Pipenv
  • Heroku CLI

Preparing for deployment

  1. Click 'use this template' at the top right of this repository. Follow the steps as as described here

  2. Navigate into the template folder cd template

  3. Install dependencies from the Pipfile

pipenv install

  1. Activate the pipenv virtual environment

pipenv shell

  1. Update your environment variables in your .env file:

    1. touch .env
    2. echo "SECRET_KEY=$(openssl rand -base64 32)" >> .env
    3. 'echo "DEBUG=True" >> .env`
  2. Test the local django server python manage.py runserver

  3. Rename the project:

    1. Run @FredPerr's script (also included in this project) to rename most instances of the project name.

    python rename-project.py PROJECT_NAME

    1. Manually rename the the heroku_django_boilerplate root folder

    At this stage, you might run into an ImportError: Couldn't import Django. Try deactivating your pipenv, deleting your Pipfile.lock, reactivating your pipenv, and reinstalling your dependencies.

  4. Update the Procfile: web: gunicorn PROJECT_NAME.wsgi

  5. Test the local heroku server heroku local or heroku local web

Deployment

  1. Commit your changes
  2. Create a heroku app for this project: heroku create. You can optionally pass in a unique project name after this command heroku create myuniqueappname
  3. Update your environment variables on the Heroku server:
    1. Run heroku config:set SECRET_KEY='YOURRANDOMSECRETKEY', using the value that was previously autogenerated and inserted into your .env file
    2. Run heroku config:set DEBUG=False
  4. Update the ALLOWED_HOSTS setting in settings.py to have the autogenerated project URL (yourappname.herokuapp.com)
  5. (optional) Check the remotes for your repository. If a second remote for Heroku has not been added, run: heroku git:remote myuniqueappaname
  6. Push your code to the main/master branch git push heroku main or git push heroku master

Voila! Open the URL heroku gives you when you run that command (or run heroku open) and you should be able to see your site.

About

Boilerplate template for Django projects to be deployed on Heroku

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published