from django.conf import settings
def my_view(self, request, *args, **kwargs):
if 'LOCAL' in settings and settings.LOCAL:
# do something
TypeError at ... 'LazySettings' 类型的参数不可迭代
那么如何检查设置是否存在?否则我得到一个属性错误。
from django.conf import settings
def my_view(self, request, *args, **kwargs):
if 'LOCAL' in settings and settings.LOCAL:
# do something
TypeError at ... 'LazySettings' 类型的参数不可迭代
那么如何检查设置是否存在?否则我得到一个属性错误。
您可以使用以下hasattr
功能:
if hasattr(settings, 'name_of_setting'):
# the setting exists
else:
# the setting does not exist