Reputation: 2027
I've been looking for some days now, if it's possible to set a context processor for a specific range of urls. But so far i haven't found anything.
I would like to calculate the count of objects in a list so in my template I could put
<ul>
<li><a href="{%url unread_mails %}">Unread mails (42)</a></li>
<li><a href="{%url deleted_mails %}">Deleted mails (5)</a></li>
</ul>
However, this would only be necessary for 5 views (could be more in the future) in the same application. Would it be possible to enable a context processor for just this app?
Upvotes: 4
Views: 636
Reputation: 82
In my case, I want my context processor to run only when admin dashboard is hit otherwise not. So I have implemented something like
def custom_context_processor(request,*args,**kwargs):
if '/' in request.META['PATH_INFO']:
return {"something"}
else:
#do something
This one worked for me
Upvotes: 1