Best practice to use django db connection in network call

339 Views Asked by At

I have two Django projects with DRF and have some Rest API's I want to use db connection of one Django project to another so i need to pass db connection/credentials over api network. I know we can get connection object using following

from django.db import connections
db_conn = connections['default']

and what am thinking is

1- to pass above db_conn in an api call as parameter to second project api but when am getting on other side its showing as string not as db connection object.

2- Another option is to pass credentials and create connection using sql alchemy in second project.

So what is the best approach in above two scenarios?. Also it would be great if you can answer how to pass db connection object in api params as object not string

1

There are 1 best solutions below

0
saro On

I dont think you can put the object as parameter in the api request. A string is the best result you will get. Besides i would not be very happy with that info in the api! Option 2 is the better aproach i would think.