我想使用以下方法在模板中加载站点名称:
{{ SITE_NAME }}
在setting.py
我有:
SITE_NAME = "MySite"
和
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
我还使用基于类的视图来加载我的视图(views.py
):
from django.views.generic import TemplateView
class MenuNavMixin(object):
def get_context_data(self, **kwargs):
context = super(MenuNavMixin, self).get_context_data(**kwargs)
return context
class AboutView(MenuNavMixin, TemplateView):
template_name = "home/about.html"
urls.py
:
url(r'^about/$', AboutView.as_view(), name='about'),
除非我专门将其添加到上下文变量SITE_NAME
中,否则我无法访问:home/about.html
import mywebsite.settings
class MenuNavMixin(object):
def get_context_data(self, **kwargs):
context = super(MenuNavMixin, self).get_context_data(**kwargs)
context['SITE_NAME'] = mywebsite.settings.SITE_NAME
return context
如果我使用以下方法,我认为情况并非如此:
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
谁能指出我正确的方向?