Mridang Agarwalla
Mridang Agarwalla

Reputation: 45018

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?

Upvotes: 4

Views: 2200

Answers (3)

Niklas R
Niklas R

Reputation: 16870

for name in filter(lambda x: x.startswith('MYAPP_'), dir(settings)):
    # ...

Upvotes: 3

andrean
andrean

Reputation: 6796

for s in dir(settings):
    print s, ':', getattr(settings, s)

Upvotes: 7

almostflan
almostflan

Reputation: 640

You should be able to call dir on it.

from django.conf import settings
print dir(settings)

Upvotes: 3

Related Questions