I want to force Django to use SSL to connect to my postgres database.
This question indicates that I need to pass sslmode=\'require\'
to the psycopg2 connec
Add 'OPTIONS': {'sslmode': 'require'},
to your database config. For example:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': "db_name",
'USER': "db_username",
'PASSWORD': "db_password",
'HOST': "db_host",
'OPTIONS': {'sslmode': 'require'},
},
}
As jklingen92 points out, if you are using a database URL, such as through django-environ, add ?sslmode=require
to the end of your database URL. For example:
postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:PORT/DB_NAME?sslmode=require