7
from django.conf import settings

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

TypeError at ... 'LazySettings' 类型的参数不可迭代

那么如何检查设置是否存在?否则我得到一个属性错误。

4

1 回答 1

14

您可以使用以下hasattr功能:

if hasattr(settings, 'name_of_setting'):
    # the setting exists
else:
    # the setting does not exist
于 2012-07-14T19:27:44.873 回答