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

  • Home
  • SEARCH
  • 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 8547471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:23+00:00 2026-06-11T13:16:23+00:00

I am looking for the following feature in django I am writing a website,

  • 0

I am looking for the following feature in django

I am writing a website, it contains many pages ex: home(displays all the books), details(selected book details), search(display the books based on search).

now the home page contains blocks like featured books, just-in books, most famous books.
details pages display selected book details and it should display featured books, most famous books.

Now my Question is featured and famous books blocks are getting repeated, so is there any way to keep the template code separately(html) and also respective view method separately. so if I call these mini templates from main templates with arguments.

So that I can keep more generalized way and without repeating the code also in future if I want to change something I can do it at one place.

I am thinking to do it with filter but is that a good way? or django provided any mechanism?

  • 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-11T13:16:25+00:00Added an answer on June 11, 2026 at 1:16 pm

    You can isolate reusable blocks of HTML into templates, and then include them in other templates with the {% include %} tag.

    They don’t take arguments, but you can either set up the main template so that the variables are set correctly, or use a {% with %} tag to set the context before the {% include %}

    As a concrete example, your view code could set up lists of books like this:

    def book_detail_view(request, book_id):
        # Get the main book to display
        book = Book.objects.get(id=book_id)
        # Get some other books
        featured_books = Book.objects.filter(featured=True).exclude(id=book_id)
        just_in_books = Book.objects.filter(release_data__gte=last_week, featured=False).exclude(id=book_id)
    
        return render("book_template.html",
                      dict(book=book,
                           featured_books=featured_books,
                           just_in_books=just_in_books))
    

    Then, in your template (book_template.html):

    <h1>Here's your book</h1>
    <!-- fragment uses a context variable called "book" -->
    {% include "book_fragment.html" %}
    
    <h2>Here are some other featured books:</h2>
    {% for featured_book in featured_books %}
        <!--Temporarily define book to be the featured book in the loop -->
        {% with featured_book as book %}
            {% include "book_fragment.html" %}
        {% endwith %}
    {% endfor %}
    
    <h2>Here are some other books we just received:</h2>
    <!-- This is a different way to do it, but might overwrite
         the original book variable -->
    {% for book in just_in_books %}
        {% include "book_fragment.html" %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the following feature describe below. The MessageFormat of the sun api
I am looking to implement a Forgot Password feature on my website. I like
I'm looking to integrate a light-weight forum feature into an existing GWT website. The
I am looking for a e-commerce solution which can allow the following feature... For
I am looking into implement a lazy load feature on image on a website,
I'm looking for the following solution in PHP. Whenever a user clicks on a
I was looking at the following code I came across for printing a string
I was looking at the following code in python: for ob in [ob for
I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
Trying to customize Symfony2 form to produce html code looking like the following example:

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.