Django & postgres & SSL

I’d thought something like this is a FAQ but the db docs on postgres don’t write a bit about forcing Django to connect using SSL to the database server.

After lots of googling (and finding hundreds of guides how to set up a Django with HTTPS) and finding out by try-and-error, behold the solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'dbname',
            'USER': 'dbuser',
            'PASSWORD': 'dbpassword',
            'HOST': 'dbhost',
            'OPTIONS': {
                'sslmode': 'require',
            },
        },
    }

← See all posts