TemplateView class and process_template_response problem

50 views
Skip to first unread message

cingusoft

unread,
Nov 14, 2012, 7:47:31 PM11/14/12
to django...@googlegroups.com
Hi All

i have a middleware that override the response.template_name variable

class MyMiddleware(object):

    def process_template_response(self,request, response):
        response.template_name = ("%s/%s"%("admin",request.template_name))

the view is very easy

class Admin_HomeView(TemplateView):
    template_name = "home.html"

and i catch an error
'WSGIRequest' object has no attribute 'template_name'

the response have no the template_name attribute
what is wrong?

thank's and have a nice day

cingusoft

unread,
Nov 15, 2012, 5:51:57 AM11/15/12
to django...@googlegroups.com
No one have experimented this problem?

Tom Evans

unread,
Nov 15, 2012, 6:01:12 AM11/15/12
to django...@googlegroups.com
The problem is that you think the request has an attribute named
template_name - it doesn't. Your CBV has that attribute, not the
request.

Responses created by TemplateView will be TemplateResponse that will
have the template_name attribute set. You don't need magic middleware
to add it in.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages