Opened 3 years ago

Closed 3 years ago

#33162 closed New feature (wontfix)

Add __file__ to Settings.

Reported by: Thomas Güttler Owned by: nobody
Component: Core (Other) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Thomas Güttler)

Sometimes you have no clue which settings file is active.

For other files I use this pattern, to see which actual file is loaded:

assert 0, mylib.__file__

Unfortunately this does not work for django.conf.settings:

AttributeError: 'Settings' object has no attribute '__file__'

It would be super cool, if this attribute would be available.

Of course I could use:

        assert 0, os.environ['DJANGO_SETTINGS_MODULE']

But sometimes the env var is not the actual file.

Change History (3)

comment:1 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:2 by Thomas Güttler, 3 years ago

Description: modified (diff)

comment:3 by Mariusz Felisiak, 3 years ago

Resolution: wontfix
Status: newclosed
Summary: AttributeError: 'Settings' object has no attribute '__file__'Add __file__ to Settings.

You can use settings.SETTINGS_MODULE to check the actual module and importlib to get the file, e.g.

>>> from django.conf import settings
>>> import importlib
>>> importlib.import_module(settings.SETTINGS_MODULE).__file__
'/django/tests/test_pg.py'

I don't think that a hook is needed in Django itself.

Note: See TracTickets for help on using tickets.
Back to Top