Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can iterate over all the settings in Django?

How can I iterate over all the Django settings? I need to read all the settings which begin with MYAPP_.

I've tried doing this:

from django.conf import settings

for setting in settings:
    print setting

...but i get the following exception:

TypeError: 'LazySettings' object is not iterable

Any ideas on how I can accomplish this?

like image 948
Mridang Agarwalla Avatar asked Dec 12 '22 21:12

Mridang Agarwalla


2 Answers

for s in dir(settings):
    print s, ':', getattr(settings, s)
like image 154
andrean Avatar answered Dec 28 '22 07:12

andrean


You should be able to call dir on it.

from django.conf import settings
print dir(settings)
like image 34
almostflan Avatar answered Dec 28 '22 07:12

almostflan