Heroku
We strongly suggest you just use Heroku to deploy your app.
The standard configuration will only cost $7/month (for a "hobby" dyno, and free database tiers). This is enough to start building on! Upgrading Postgres will be the most likely next step, especially because it will get you "rolling backups" ($50/month).
To set up Heroku, take a look at the quickstart guide.
Procfile
When you use the Forge buildpack,
Heroku will automatically set up a Procfile
for you.
Here's what it does:
web: forge serve
release: forge pre-deploy
If you need to customize your Procfile
, simply add one to your repo!
Running commands on production
There will be times when you need to run commands remotely on your production app and production database.
If you need to run a specific manage.py
command, you can do it directly like this:
heroku run python app/manage.py createsuperuser
heroku run python app/manage.py shell
But if you're not sure of the exact command,
it's best to just run bash
and use the shell from there:
heroku run bash
Otherwise you'll spend a lot of time waiting for the temporary dynos to start/stop, just to tell you there was a typo or print out some help text for your next attempt.
Media and uploads
One trick with deploying to Heroku is that you can't just save uploaded or generated files to the server (ex. when a user uploads an avatar, or you generate and save a PDF). If you do, you'll notice that they disappear! The filesystem on Heroku is ephemeral, so you need to use something like AWS S3 for long-term file storage.
Depending on your app, you may not need to store files like this at all. Because it isn't always needed, Forge doesn't come with a solution for file storage.
If you need to store uploaded files (typically because you want to use models.FileField
),
then we recommend installing up django-storages.
If you're using AWS for anything else,
than AWS S3 may be an easy and commonly-used choice for the backend.
If you have any questions, feel free to ask in the GitHub Discussions.
Monitoring
Once your site is up, there a few things to consider:
Error monitoring
Forge Pro comes with Sentry integration →
Performance monitoring
If you use Professional dynos (i.e. standard-1x
) can set Threshold Alerts on Heroku.
These can alert on slow response times and failed requests.
You can also use Sentry's performance monitoring which ties directly into your error monitoring.
Logging
You can view your logs with the Heroku CLI:
heroku logs --tail
By default, these aren't persisted anywhere. If you want to store logs, you'll need to hook up a one of the Heroku add-ons or set up your own log drain.
Backups
The easiest thing to do regarding database backups is to use at least the standard-0
tier of Heroku Postgres ($50/mo).
This gives you the ability to "roll back" to a previous state of your database in the last X days,
as well as manually and automatically create standalone backups.