Different models in child and Parent Templates

38 views
Skip to first unread message

jithu s jacob

unread,
May 1, 2017, 7:20:37 AM5/1/17
to Django users
I am using parent template as base which has a side nav bar. the child template keeps changing with clicking of buttons.
 
My child template changes correctly with call to different views through the URLs.

Now I want to add some data from model i the parent template irrespective of the view/model  or URL being called in the child template.

is there any easy was to do this.

for now I am writing additional context variables for parent template for all the child views. But this is not feasible

chuck.h...@packetviper.us

unread,
May 1, 2017, 12:33:49 PM5/1/17
to Django users
Please be more specific about your issue. How are you rendering your templates? Can you paste into a response your views.py and urls.py for the relevant apps?

jithu s jacob

unread,
May 2, 2017, 11:07:03 AM5/2/17
to Django users
<div class="container-fluid">
  <div class="row content">
    {% include 'blog/navbar.html' %}

    <div class="col-sm-9">
      <h4><small>RECENT POSTS</small></h4>
      <hr>
      {%block content %}
      {% endblock%}
                
    </div>
  </div>
</div>

class HomeView(ListView):
template_name='blog/home.html'
model=Blog

class BlogView(DetailView):
template_name='blog/blog.html'
model=Blog


class ContactView(ListView):         --------> i don't need model blog for contactview.But I am using it to populate side navbar.If I have other similar                                                                                        views.should it done in the same way
template_name='blog/contact.html'
model=Blog

chuck.h...@packetviper.us

unread,
May 2, 2017, 1:36:35 PM5/2/17
to Django users
So what would you like the ContactView to populate into the nav bar?  Without a data model, there is nothing to render.

Remember that {% include 'blog/navbar.html' %} will not access/render that "url", it will simply paste in the contents of that file(template) into the template before rendering (i.e. expanding tags), so the tags in that file will be expanded based on whatever Context dict is passed to the method which is rendering it.

But I may not be understanding the problem clearly.
Reply all
Reply to author
Forward
0 new messages