Reputation: 398
I have a view
, which return context {}. I need to use these context variables not in one template.html
, - but in several templates. How can I do this?
return render(request, 'cart/cart_detail.html', {
'order':order,
'order_item':order_item,
'total':total}
Upvotes: 0
Views: 370
Reputation: 2165
i guess you could use context processors, that's what i use to get my conxtext inside navbar anf therfore show it in all my templates:
1 - create a context_processors.py in your app then add your function in it.
2 - in settings.py
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
....
'your_app_name.context_processors.your_function_name',
],
},
},
]
3 - use it in your templates:
def your_function(request):
// ... whatever you have or nothing
return dict(order=order,order_item=order_item,total=total)
(i could forgot something, you could check the docs), hope that helps
Upvotes: 1