Template Inheritance doesnot work in Django

84 views Asked by At

I have base.html (which is my home page). It has navbar which is in navbar.html and some sliders in base.html itself. I have created ProductList view which render context(i.e products), which is used in product_list.html to make values dynamic.

Now my problem is I don't want to include my ProductList view in my product.urls because i don't want it to be rendered in new page. Instead I want to include product_list.html in base.html inorder to show it in my home page rather than in product page just like in normal ecommerce site.

So, I didn't include ProductList in product.urls and included that template in base.html using include template-tag. But it didn't show my products. When i tried to render products in separate page it works.

Is there any method to do this?

1

There are 1 answers

0
Gnanavel On

I think you forget to pass the context.In your views.py, pass the context to the function which renders the base.html

For example:

def index(request):
    context = {'product':products}  #Pass your products
    return render(request,'base.html',context)