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 9032389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:58:14+00:00 2026-06-16T07:58:14+00:00

I have problem with Django templates. I want to create a base html, which

  • 0

I have problem with Django templates. I want to create a base html, which I will use to display posts. I call a template from view, which includes an html file, where the file extends the base html.

view

def main(request):
    all_posts = News.objects.all()
    return render_to_response("index.html", {'all_posts': all_posts})

template — index.html

<div id="content">
    {% include 'content.html' with posts=all_posts%}
</div>

content.html

{% extends "content_base.html" %}

{% for post in posts %}
    {% block date_of_post %} {{ post.date }} {% endblock %}
    {% block post_author %} {{ post.author }} {% endblock %}
    {% block post %} {{ post.content }} {% endblock %}
{% endfor %}

content_base.html

<div class="post">
    <h2 class="title"><a href="#">{% block blabla %}{% endblock %}</a></h2>
    <p class="meta"><span class="date">{% block date_of_post %}{% endblock %}</span><span class="posted">Posted by <a href="#">{% block post_author %}{% endblock %}</a></span></p>
    <div style="clear: both;">&nbsp;</div>
    <div class="entry">
        <p>
            {% block post %} {% endblock %}
        </p>    
        <p class="links">
            <a href="#" class="more">Read More</a>
            <a href="#" title="b0x" class="comments">Comments</a>
        </p>
    </div>
</div>

But it seems like I cannot pass the *all_posts* variable to content.html. What is the problem here? Am I doing something wrong?

Thanks in advance.

  • 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-06-16T07:58:15+00:00Added an answer on June 16, 2026 at 7:58 am

    You should move the loop into index.html, and include content_base.html directly. So index.html becomes:

    <div id="content">
        {% for post in posts %}
            {% include 'content_base.html' %}
        {% endfor %}
    </div>
    

    and content_base.html is

    <div class="post">
        <h2 class="title"><a href="#">{{ post.title }}</a></h2>
        <p class="meta"><span class="date">{{ post.date }}</span><span class="posted">Posted by <a href="#">{{{ post.author }}</a></span></p>
        <div style="clear: both;">&nbsp;</div>
        <div class="entry">
            <p>
                {{ post.content }}
            </p>    
            <p class="links">
                <a href="#" class="more">Read More</a>
                <a href="#" title="b0x" class="comments">Comments</a>
            </p>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using the '|default' in django templates. If I do this
I am a beginner of Django. Now, I have a problem of getting templates.
I have a problem with the jquery-autocomplete pluging and my django script. I want
I have problem about django template-db query relationship. For example, I created two tables
I've got a problem with using django's {% trans %} template function. I have
I have an HTML django template page that is both RTL and LTR (depends
i have problem with django's named urls which is included with include keyword. In
I have a problem with django model objects where I have overridden __hash__ ()
I have an odd problem with Django. I have a set of objects that
I'm trying to migrate django apps, and i have problem with one. When i

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.