I have a django project on a Digital Ocean server. From my local machine, I connect to the database through ssh:
ssh -L 63333:localhost:5432 me@my.server
You can use something like below
from django.db import connections conn = connections['default'] conn.connect()
or
from django.db import connection connection.connect()