This git repository is meant to be a bare-bones template for creating Django apps that can quickly be deployed to Heroku.
This template uses pipenv and contains the following packages:
- django
- gunicorn
- dj-database-url
- psycopg2-binary
- whitenoise
- django-environ
- 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
You need to have the following installed on your system:
- Python
- Pipenv
- Heroku CLI
-
Click 'use this template' at the top right of this repository. Follow the steps as as described here
-
Navigate into the template folder
cd template
-
Install dependencies from the Pipfile
pipenv install
- Activate the pipenv virtual environment
pipenv shell
-
Update your environment variables in your
.env
file:touch .env
echo "SECRET_KEY=$(openssl rand -base64 32)" >> .env
- 'echo "DEBUG=True" >> .env`
-
Test the local django server
python manage.py runserver
-
Rename the project:
- Run @FredPerr's script (also included in this project) to rename most instances of the project name.
python rename-project.py PROJECT_NAME
- 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 yourPipfile.lock
, reactivating your pipenv, and reinstalling your dependencies. -
Update the
Procfile
:web: gunicorn PROJECT_NAME.wsgi
-
Test the local heroku server
heroku local
orheroku local web
- Commit your changes
- Create a heroku app for this project:
heroku create
. You can optionally pass in a unique project name after this commandheroku create myuniqueappname
- Update your environment variables on the Heroku server:
- Run
heroku config:set SECRET_KEY='YOURRANDOMSECRETKEY'
, using the value that was previously autogenerated and inserted into your .env file - Run
heroku config:set DEBUG=False
- Run
- Update the ALLOWED_HOSTS setting in
settings.py
to have the autogenerated project URL (yourappname.herokuapp.com
) - (optional) Check the remotes for your repository. If a second remote for Heroku has not been added, run:
heroku git:remote myuniqueappaname
- Push your code to the main/master branch
git push heroku main
orgit 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.