Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:48:00+00:00 2026-05-13T13:48:00+00:00

I have a template that includes several tables. I want to use a sub-template

  • 0

I have a template that includes several tables. I want to use a sub-template which renders these tables in the same way. I can get it to work for a single table, by setting the context in the view and passing that to the template. But how do you change the data for to render another table for different data?

**'myview.py'**

from django.shortcuts import render_to_response
table_header = ("First Title", "Second Title")
table_data = (("Line1","Data01","Data02"),
              ("Line2","Data03","Data03"))
return render_to_response('mytemplate.html',locals())

**'mytemplate.html'**

{% extends "base.html" %}
{% block content %}
<h2>Table 01</h2>
{% include 'default_table.html' %}
{% endblock %}

**'default_table.htm'**

<table width=97%>
<tr>
{% for title in table_header %}
<th>{{title}}</th>
{% endfor %}
</tr>
{% for row in table_data %}
<tr class="{% cycle 'row-b' 'row-a' %}">
{% for data in row %}
<td>{{ data }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>

If I added more data in the ‘myview.py’, how would you pass it so the second set of data could be rendered by the ‘default_table.html’?

(Sorry … I’m just starting out with Django)

ALJ

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:48:01+00:00Added an answer on May 13, 2026 at 1:48 pm

    You can try the with template tag:

    {% with table_header1 as table_header %}
    {% with table_data1 as table_data %}
        {% include 'default_table.html' %}
    {% endwith %}
    {% endwith %}
    
    {% with table_header2 as table_header %}
    {% with table_data2 as table_data %}
        {% include 'default_table.html' %}
    {% endwith %}
    {% endwith %}
    

    But I don’t know if it works, I didn’t try it myself.

    Notice: If you have to include this very often, consider to create a custom template tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a index.php file that will include several external files: content/templates/id1/template.php content/templates/id2/template.php content/templates/id3/template.php
I have a Meteor template that includes the following: {{#with selected_recipe}} {{>recipe}} {{/with}} In
I have a ListView template that's being used in several places and I'd like
I have a Django template that I want to extend in multiple places. In
I have been writing several class templates that contain nested iterator classes, for which
In my DB schema I have several tables that will be related to a
I have a little statistics block that I want to be available in several
How can I modify the below code so that I could use the same
I have this Visual Studio solution that includes a project that has a template
I have created an Xcode 4 project template for iOS that relies on several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.