Home > Net >  How to access the value of constant in settings.py
How to access the value of constant in settings.py

Time:02-10

I'd like ask about how to access the value of a constant declared in setting.py the following way:

PAYMENT_VARIANTS = {
'redsys': ('payments_redsys.RedsysProvider', {
    'merchant_code': '123456789',
    'terminal': '1',
    'shared_secret': 'aaaaaaaaaaaaaaaaaaaaaaaaaa',
    'currency': '978',
})

}

I can import:

from django.conf import settings

But, how I can access the value of field 'currency' or other at this level.

Thanks, regards,

CodePudding user response:

You can do for example:

from django.conf import settings

if settings.DEBUG:
    # Do something

In your case would be something like:

settings.PAYMENT_VARIANTS['redsys']

CodePudding user response:

You can access the PAYMENT_VARIANTS dictionary using settings.PAYMENT_VARIANTS and can access the key currency like this

settings.PAYMENT_VARIANTS['redsys'][1]['currency]
  • Related