Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
striveforbest opened this issue Mar 31, 2021 · 4 comments
Open

Comments

@striveforbest
Copy link

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?

@brianhelba
Copy link
Contributor

@striveforbest

This should have it:

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

@brianhelba
Copy link
Contributor

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

@striveforbest
Copy link
Author

@brianhelba that'd be amazing!

@paduszyk
Copy link
Contributor

@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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants