Skip to content

Instantly share code, notes, and snippets.

@michealjroberts
Last active Feb 17, 2020
Embed
What would you like to do?
Django 3.0 DB Info Management Command
from django.db import connection
from django.core.management.base import BaseCommand
from django.conf import settings
class Command(BaseCommand):
help = 'Displays The Currently Connected DB Settings'
def handle(self, *args, **kwargs):
print("The connection vendor is {}".format(connection.vendor))
print(
"The current database engine is {ENGINE}".format(**connection.settings_dict)
)
print(
"Currently connected to host {HOST} on port {PORT}".format(**connection.settings_dict)
)
if connection.settings_dict['OPTIONS']['sslmode'] == 'require':
print(
"The database is using encrypted transport methods: SSL is on!"
)
if connection.settings_dict['ATOMIC_REQUESTS']:
print(
"The database is using a per view transation based approach - atomic requests are on."
)
else:
print(
"The database is not using a per view transation based approach - atomic requests are off."
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment