Code

Opened 3 years ago

Closed 3 years ago

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

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 3 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 (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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.