60π
β
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
π€Zags
9π
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)
π€jklingen92
- [Django]-How to make python on Heroku https only?
- [Django]-Is_valid() vs clean() django forms
- [Django]-How do I access the child classes of an object in django without knowing the name of the child class?
4π
If youβre using dj_database_url you can pass ssl_require=True
which sets the option for you.
import dj_database_url
DATABASES['default'] = dj_database_url.config(ssl_require=True)
π€frmdstryr
- [Django]-Proper way to test Django signals
- [Django]-Is Django post_save signal asynchronous?
- [Django]-Suddenly when running tests I get "TypeError: 'NoneType' object is not iterable
0π
Edit the settings.py
file like this:
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# },
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': 'server-ip',
'PORT': '5432',
'NAME': 'database-name',
'USER': 'username',
'PASSWORD': 'password',
'OPTIONS': {
'sslmode': 'require',
'sslcert': '/path/to/file',
'sslkey': '/path/to/file',
'sslrootcert': '/path/to/file',
},
},
}
references visit here
π€Sumit Kumar
- [Django]-How do I turn MongoDB query into a JSON?
- [Django]-Workflow frameworks for Django
- [Django]-Django Rest Framework β Updating a foreign key
Source:stackexchange.com