pip install django-heroku
Handling static files
At one point or another you want to add assets like CSS files, JavaScript files or images to your project.
The adviced solution is to store the files externally (like an AWS S3 bucket). For prototypes or smaller projects it is easier to let Django serve the static files on production as well. While Django handles static files locally just fine, the Heroku app needs a bit of configuration.
Add django-heroku
With django-heroku Heroku provides a handy Python package that helps dealing with configuration settings for Heroku. Especially the handling of settings, static files and logging is much easier with it.
PIP grabs all required dependencies when installing django-heroku
.
This includes:
-
dj-database-url`
-
whitenoise
-
psycopg2
-
django
(We already have this one! ๐)
Install django-heroku
:
Add it to our settings.py file:
import django_heroku
django_heroku.settings(locals())
Update our requirements
Now that we have two new modules in our project, letโs update our requirements.
Update requirements.txt:
pip freeze > requirements.txt
Commit the code
If you run git status
you will see, that we updated requirements.txt and settings.py.
Now we can stage and commit our changes:
git add .
git commit -m "Configure static files handling ๐"