Re: TemplateView class and process_template_response problem

2012-11-15 Thread Tom Evans
On Thu, Nov 15, 2012 at 12:47 AM, cingusoft  wrote:
> 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?
>

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: TemplateView class and process_template_response problem

2012-11-15 Thread cingusoft
No one have experimented this problem?

El jueves, 15 de noviembre de 2012 01:47:31 UTC+1, cingusoft escribió:
>
> 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
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eI6CxJfop3EJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



TemplateView class and process_template_response problem

2012-11-14 Thread cingusoft
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


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/LgLow7MLNyYJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.