You need to call "TemplateResponse" in your views for "process_template_response" to be called in your middleware. So in you view, instead of doing: return render(request,'some template' , {'context':context}) You do: return TemplateResponse.
Thanks. jenia On Sep 28, 6:25 pm, jenia ivlev <jenia.iv...@gmail.com> wrote: > Hello: > > I have defined a middleware class. and i have added it to the > middleware_classes attribute in setting. When a request comes in, the > middleware class gets created (the debugger catches the code when the > breakpoint is on the class CommonFiilter(): line) > > Now i expect the function def process_template_response(self, > request, response): to get called. I have debug point on the inside of > the function and the debugger never traps the execution. The debugger, > though, traps the execution at the line where the function name and > parameters are defined. > This is the class: > > class CommonFilter(): DEBUGGER BREAKS HERE > def process_template_response(self, request, response): DEBUGGER > BREAKS HERE > if response.template_name=='store/index2.html': NOT HERE(or > after this line) > catnames=getCategories() > > response.context_data.update({'catnames':catnames,'user':request.GET.get(key='user',default=None)}) > return response > > Hello: > > I have defined a middleware class. and i have added it to the > middleware_classes attribute in setting. When a request comes in, the > middleware class gets created (the debugger catches the code when the > breakpoint is on the class CommonFiilter(): line) > > Now i expect the function def process_template_response(self, > request, response): to get called. I have debug point on the inside of > the function and the debugger never traps the execution. The debugger, > though, traps the execution at the line where the function name and > parameters are defined. > This is the class: > > class CommonFilter(): DEBUGGER BREAKS HERE > def process_template_response(self, request, response): DEBUGGER > BREAKS HERE > if response.template_name=='store/index2.html': NOT HERE(or > after this line) > catnames=getCategories() > > response.context_data.update({'catnames':catnames,'user':request.GET.get(key='user',default=None)}) > return response > > Also tried this: > > class CommonFilter(): DEBUGGER BREAKS HERE > def process_template_response(self, request, response): DEBUGGER > BREAKS HERE > if response.template_name=='store/index2.html': NOT HERE(or > after here) > catnames=getCategories() > response.context_data['catnames']=catnames > > response.context_data['user']=request.GET.get(key='user',default=None) > return response > > Just in case, this is the setting MIDDLEWWARE_CLASSES variable: > > MIDDLEWARE_CLASSES = ( > 'store.models.CommonFilter', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > ) > > store is an app in this project and ofcourse CommonFilter is defined > in models.py. > > Why is the function process_template_response function not being > executed? > > Thanks for your time and kind concern. Sorry for the -- 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.