#How do I initialize an SDK globally in Django?

10 messages · Page 1 of 1 (latest)

alpine garnet
#

I have an SDK to connect with a payment gateway, and I’m currently using it in my view. So, on every request, it initializes with the connection settings. Is there a way I can do this globally?

mild ingot
#

Potentially in the wsgi file?

alpine garnet
#

Hmm into this archive wsgi I inicializa the SDK and after how i can use in view?

covert magnet
#

Is there a reason you can't write a function that initialises the client object and returns it, and just call that from each view you need it?

alpine garnet
#

You can show me one example?

covert magnet
#
def get_payment_client():
    client = Client()
    client.do_whatever_you_need_to_initialize()
    return client

def my_view(request):
    client = get_payment_client()
    … 
winter rover
#

Depending on the implementation and use case, I may put it in the settings or its own module

#

Importing the initialized version of the client should be enough, it doesn't matter much where you put it; but I'd prefer a place that is imported and executed during Django's initialalization

alpine garnet
#

The sdk is for connect with Payment Gateway, i think i can set The inicial configuration in my settings and call in my view the class

quiet meteor
#

context processors?