Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django argument of type 'LazySettings' is not iterable; how then to check if a setting exists?

from django.conf import settings

def my_view(self, request, *args, **kwargs):
    if 'LOCAL' in settings and settings.LOCAL:
        # do something

TypeError at ... argument of type 'LazySettings' is not iterable

How then to check if a setting exists? Otherwise I get an attribute error.

like image 543
B Robster Avatar asked Jul 14 '12 19:07

B Robster


1 Answers

You can use the hasattr function:

if hasattr(settings, 'name_of_setting'):
    # the setting exists
else:
    # the setting does not exist
like image 168
Simeon Visser Avatar answered Nov 19 '22 13:11

Simeon Visser