S
S
Salavat Sharapov2014-07-07 18:39:35
Django
Salavat Sharapov, 2014-07-07 18:39:35

How to be C or B views.py?

Good afternoon!
Trouble again.

class NewsPageView(ListView):
    model = News
    # template_name =news.html
    def get_template_names(self, **kwargs):
        qs = Model.objects.filter(site=self.request.site)
        for data in qs:
            if data.template_site == '1':
                return 'news1.html'
            else:
                return 'news.html'

    def get_queryset(self, **kwargs):
        return News.objects.on_site(site=self.request.site)
    def get(self, request, *args, **kwargs):
        result = News.objects.on_site(site=self.request.site)
        if request.GET:
            query = request.GET.get("q")
            result = result.filter(Q(title__icontains=query)|Q(short_text__icontains=query)|Q(text__icontains=query))
        return render(request, self.template_name, {'news': result})

I need to change the template depending on the user. BUT at the end of the code, template_name weighs, which says that the template was not found. Although if you remove it (template_name, together in a function), then the norms work. But this part of the code is definitely needed, unfortunately it was written by a person much more experienced than me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Salavat Sharapov, 2014-07-08
@desperadik

return render(request, self.get_template_names(*args), {'news': result})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question