在TemplateView中使用变量

时间:2019-06-30 05:59:39

标签: python django python-3.x

我以前在Django中用如下函数定义页面:

 def pdf(request):
     return render(request, 'blog/pdf.html', {'title': 'PDF files'})

我在Title变量中使用html页面标题。我开始在页面上使用TemplateView类,但不确定如何在类似的内容中使用相同的title

class About(LoginRequiredMixin, TemplateView):
    template_name = 'blog/about.html'

1 个答案:

答案 0 :(得分:2)

尝试一下

class About(LoginRequiredMixin, TemplateView):
    template_name = 'blog/about.html'

    def get_context_data(self, *args, **kwargs):
        context = super(About, self).get_context_data(*args, **kwargs)
        context['title'] = 'PDF files'
        return context
相关问题