Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use variable with TemplateView

I used to have my pages in Django defined with functions like this:

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

Where I was using a Title var for html page title. I started to use a TemplateView class for my pages and I'm not sure how to use the same title inside of something like this:

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

1 Answers

Try this,

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
like image 122
shaik moeed Avatar answered May 05 '26 12:05

shaik moeed