Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#16710 closed Bug (invalid)

multiple templates per view in class based views do not work

Reported by: tomaz.stucin@… Owned by: nobody
Component: Generic views Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If we have a cbv:

class IndexView(TemplateView):
    template_name = ['web/index.html', 'index.html']

and no matter if the template exists or not we always get the exception:

"sequence item 0: expected string, list found" in ..Python-2.7.1/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/template/ in select_template, line 203

The problem is that Django encloses the above array in an array, so template_name_list = [['web/index.html', 'index.html']] in select_template

The error is (i guess) in Django-1.3-py2.7.egg/django/views/generic/ in line 109 where we have:

return [self.template_name]

while it should be:

return self.template_name

it works for me but I am not sure if that fix is ok.

btw: I also checked the dev trunk and the array enclosing is still there


Change History (3)

comment:1 Changed 6 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

template_name is just the name of a template. I don't understand why you attempt to set it to a list.

See and

comment:2 Changed 6 years ago by tomaz.stucin@…

because before class based views i was able to do:

return render_to_response(['web/index.html','index.html'], dict({'object':o}), context_instance=RequestContext(request))

in the first array i could specify more than one template

i'd like to have the same functionality as before the class based views so i supposed the template_name variable was the same thing. this functionality is provided by django.template.loader.select_template ( which is actually called by the CBV code.

sorry if i was wrong but i just could not happen to find how to implement the same with CBV.


Note: See TracTickets for help on using tickets.
Back to Top