Reputation: 37
i have a project with different views and different function on it. i want to access and display context of one of view in other html app. this my code
washer.views.py
def Product_list_view(request):
product_list_view = Product.objects.all()
best_post = Product.objects.order_by('timefield')[0:2]
context = {
"product_list_view": product_list_view,
'best_post':best_post
}
template_name = "product_list_view.html"
return render(request,template_name,context)
gasket.views.py
def home(request):
template= "base.html"
return render(request,template,context={})
how i can access context of product_list_view and show it in base.html ? can i set one html to two different views in different app ? and access to context both of them ? what i have to do ? tnx for help me .
Upvotes: 0
Views: 32
Reputation: 5793
I'm not sure what you're actually trying to achieve here but you could simply rewrite gasket.views.py
as
def home(request):
template= "base.html"
context = {
"product_list_view": Product.objects.all(),
'best_post':Product.objects.order_by('timefield')[0:2]
}
return render(request,template,context={})
Clearly you will need to add from washer.models import Product
Upvotes: 1