Configuring Django for production
In this section, we will learn about a few key configurations we need to set before deploying to production. We will first discuss the configuration we need to update the settings.py
file:
- Update the
SECRET_KEY
value and pass it via the environment variable - Set
DEBUG = False
for production so that sensitive information via an error stacktrace is not shown, whenever there is an error in the Django app - Set
ALLOWED_HOSTS = ["dip.com", "xyz.com"]
, and list all the domains that the Django project would be served on - Set
APPEND_SLASH = True
so that if any request is missing a slash at the end, Django can add a slash automatically - Set
TIME_ZONE
appropriately
There are a few more configurations that you can update in the Django settings. They depend on the Django project use case. Apart from the preceding mentioned settings, let’s learn about a couple of other configurations we need to perform:
-
...