Deploy a Django App
The sample app is deployed at https://django.app.render.com.
Create a new PostgreSQL database on Render.
Fork render-examples/django-quick-start and create a new Web Service, giving Render’s GitHub app permission to access your forked repo.
To make sure Django allows requests on your Render host, we’ve modified the following line in
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=[env('RENDER_APP_HOSTNAME', default='')])
RENDER_APP_HOSTNAMEis the hostname for your Render app when it is first created. If you add a custom domain to your app, make sure to add it to
Pythonfor the environment and use the following values during creation:
Here are the contents of the build script:
#!/usr/bin/env bash pip install -r requirements/production.txt python manage.py collectstatic python manage.py migrate
It’s simply executing commands needed to build and deploy a Django site on each push to your repo.
It starts Gunicorn and automatically uses the
PORTenvironment variable set by Render.
Add the following environment variables under the Advanced section:
The internal connection string for the database you created above.
A sufficiently strong secret. You can generate a secret locally by running
echo "$(openssl rand -base64 32)"
The output of this command in your terminal:
echo $(base64 /dev/urandom | tr -dc 'A-HJ-NP-Za-km-z2-9' | head -c32)/
4This will start four Gunicorn workers for your app.
That’s it! Your app will be live on your Render URL as soon as the build finishes.
Once it’s live, create a new Django admin account by running this command in Render’s web shell:
$ ./manage.py createsuperuser
The sample app isn’t configured to use third-party services for external file storage, error reporting or email. You can enable these services by adding the relevant environment variables listed here.