django-configurations icon indicating copy to clipboard operation
django-configurations copied to clipboard

How can i get a name of the currently loaded/used settings class?

Open striveforbest opened this issue 4 years ago • 4 comments

I know I can use os.getenv but I'd like to be able to get the name of the currently used django-configurations settings class name in the code? How do I know I'm in Prod vs Development etc?

striveforbest avatar Mar 31 '21 02:03 striveforbest

@striveforbest

This should have it:

from django.conf import settings
configuration_class_name = settings.CONFIGURATION.split('.')[-1]

brianhelba avatar Oct 28 '21 16:10 brianhelba

We should document the fact that settings.CONFIGURATION exists, so I'm leaving this issue open.

brianhelba avatar Oct 28 '21 16:10 brianhelba

@brianhelba that'd be amazing!

striveforbest avatar Oct 28 '21 16:10 striveforbest

@brianhelba @striveforbest I think, that a utility for returning the configuration class itself would also be a nice feature... Even if it is as simple as:

from django.conf import settings
from django.utils.module_loading import import_string

def get_configuration_class():
    return import_string(settings.CONFIGURATION)

It could be LRU cached, of course...

paduszyk avatar Feb 14 '24 14:02 paduszyk