6

在我的views.py我有

from django.conf import settings

  def site_view(request):
    ...
    if some_var == settings.MY_SETTING:
  ...

该值MY_SETTING在 中定义settings.py。但是,当我尝试加载视图时出现以下错误:

Exception Type:    AttributeError
Exception Value:   'function' object has no attribute 'MY_SETTING'

这是怎么回事?

4

1 回答 1

13

如何导入设置,例如:

from django.conf import settings as conf_settings

然后:

if some_var == conf_settings.MY_SETTING:
于 2012-12-13T12:07:16.047 回答