1👍
✅
It sounds like you want to add certain variables to the context of every view, rather than just this one.
One way to do it is using a context processor:
# myapp/context_processors.py
def notifications(request):
"Context processor for adding notifications to the context."
return {
'unseen_notifications': Notification.objects.filter(
body__user=request.user).filter(viewed=False),
'seen_notifications': Notification.objects.filter(
body__user=request.user).filter(viewed=True),
}
You’d also need to add the context processor to TEMPLATE_CONTEXT_PROCESSORS:
# settings.py
...
TEMPLATE_CONTEXT_PROCESSORS = (
...
'myapp.context_processors.notifications',
)
1👍
I think it’s impossible to include template view via “include” template tag. Include loads template in current context https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include.
It seems to me that you should use custom template tag for your purpose.
https://docs.djangoproject.com/en/dev/howto/custom-template-tags/
- [Django]-Django Rest Framework JWT 400 Bad Request
- [Django]-Trouble with pycurl.POSTFIELDS
- [Django]-Don't include blank fields in GET request emitted by Django form
- [Django]-Django ImageField not uploading the image
Source:stackexchange.com