Force SSL for Django Postgres connection

前端 未结 3 1886
一整个雨季
一整个雨季 2021-02-07 03:13

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

3条回答
  •  有刺的猬
    2021-02-07 03:34

    If you're configuring a database URL, you can pass options as query parameters:

    DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME?sslmode=require
    

    This works with both Django Configurations and with Django Environ. Django Configurations is built off of dj_database_url, so you can also pass ssl_require=True as @frmdstryr said:

    DATABASES = values.DatabaseURLValue(environ_required=True, ssl_require=True)
    

提交回复
热议问题