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.
You can use the hasattr
function:
if hasattr(settings, 'name_of_setting'):
# the setting exists
else:
# the setting does not exist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With