在views.py我使用render().
在 app -> middleware.py 我有这个代码:
from django.conf import settings
class NoTrackingMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
return response
def process_template_response(self, request, response):
no_tracking = True if request.GET.get("NO_TRACKING", default=False) is not False else False
pub_id = "PUBLISHER_TEST" if no_tracking is True else settings.WFF_PUB_ID
response.context_data["no_tracking"] = no_tracking
response.context_data["pub_id"] = pub_id
return response
在settings.py我有:
MIDDLEWARE = [
...
'app.middleware.NoTrackingMiddleware',
]
然而,如果我在它处放置一个断点,process_template_response它就会被忽略并且pub_id总是空的。
为什么?
呼唤远方
相关分类