I have a base.html which essentially provides the navigation for my app.
I want to be able to add some stats into the nav bar - so I am trying to render them onto base.html
The same script works, if I change base.html to home.html, but I don't want to repeat the same code on every page, to retain the stats when I navigate away from home.
Here is my view:
def stats(request):
incompletetasks = Todo.objects.filter(complete=False, creator=request.user).count()
shared = Todo.objects.filter(Q(shareslotone=request.user) | Q(shareslottwo=request.user) | Q(shareslotthree=request.user) | Q(shareslotfour=request.user) | Q(shareslotfive=request.user)).count()
closedtasks = Todo.objects.filter(complete=True, creator=request.user).count()
context = {'incompletetasks':incompletetasks, 'shared':shared, 'closedtasks':closedtasks}
return render(request, 'base.html', context)
How can I make this render to base.html, rather than copying the same code for every page?
Thanks
You can use template tag for it
your_file.html
Note:This if for only one count modifiy as per requirements