henrich
henrich

Reputation: 627

Can you refer to more than one base template in django?

I have a Django app with one base template called "base.html". This template provides for the look and feel of all pages in the website. On many - though not all - of these pages, I want to pull data from my database and display it in a consistent format. I'd like to create the template for that format in a different base called, say, "base2.html". This would mean that on pages where I present data, I will need to extend both "base.html" and "base2.html". How do I extend from two html pages on the same page?

Upvotes: 2

Views: 932

Answers (1)

Prabhakar Shanmugam
Prabhakar Shanmugam

Reputation: 6154

I would try this,

in views where you want a different base I would send a key in request data like so

In views.py

def some_view_one(request):
    different_base =  "base1.html"
    return render(request, 'customer/parent_template.html', {'different_base': different_base})

def some_view_two(request):
    different_base =  "base2.html"
    return render(request, 'customer/parent_template.html', {'different_base': different_base})

In parent_template.html in the very first line.

{% extend different_base %}

Note here that view_one would extend base1.html and view_two would extend base2.html

Haven't tried the same.

Please let me know.

Upvotes: 2

Related Questions