Opened 13 years ago

Closed 13 years ago

Last modified 13 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

Description

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/loader.py 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/base.py 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

tnx

Change History (3)

comment:1 by Aymeric Augustin, 13 years ago

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 https://docs.djangoproject.com/en/dev/topics/class-based-views/ and https://docs.djangoproject.com/en/dev/ref/class-based-views/

comment:2 by tomaz.stucin@…, 13 years ago

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 (https://docs.djangoproject.com/en/dev/ref/templates/api/#the-python-api) 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.

tnx

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