<aside> 🔥 You will need to do this for both the dev environment (we'll use a local Postgres database for that) and for the production environment, on Render.
</aside>
To set up Postgres in your dev environment, follow these instructions:
First you’ll need to set up a free account on Render.com. You do not need to enter credit card information to set up your account. We’ll use their free plan.
<aside>
⚙ This assumes you’re using django-environ
and have a .env
file.
</aside>
RENDER_EXTERNAL_HOSTNAME
and RENDER
will be set by Render in the production environment. We need to make sure that Django knows it can serve your application in production by adding the Render hostname to the ALLOWED_HOSTS
setting.
# settings.py
# configure a default value that will be used in the development environment
env = environ.Env(
# set casting, default value
DEBUG=(bool, False),
USE_S3=(bool, False),
RENDER=(bool, False) # <--- add this
)
...
# add this
if env("RENDER"):
ALLOWED_HOSTS.append(env("RENDER_EXTERNAL_HOSTNAME"))
We can’t run commands on a command line on Render’s free tier, so we need to create a superuser programmatically as part of the build script. We’ll create a custom Django management command to do this.