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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:08:40+00:00 2026-05-13T23:08:40+00:00

I have a Django template that I want to extend in multiple places. In

  • 0

I have a Django template that I want to extend in multiple places. In some the div must be inside a form, and in others it must not be. To do this I put a block above and below the div so I could add and in them respectively.

Desired:

<form>
<div class="my_div">
  {% block div_content %}
    ...
  {% endblock %}
</div>
</form>

Template:

{% block div_top %}{% endblock %}
<div class="my_div">
  {% block div_content %}
  {% endblock %}
</div>
{% block div_bottom %}{% endblock %}

Looking at this I can’t help but think that there is a better way to do it. What is the standard Django way of doing this?

  • 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-13T23:08:41+00:00Added an answer on May 13, 2026 at 11:08 pm

    Use of multiple base templates is a solution I’ve seen a few teams use. For example, you might just add an additional base template called “base_with_form.html”. Templates that need the form extend this base template.

    One thing that has helped me is to think of laying out template directories in a manner similar to Python packages. I typically include a base.html per directory (ala init.py) even if it is just a placeholder. Every base file extends a base file in its parent directory. Additional specializations of styles for multiple templates in the same directory are accomplished by adding copies of the local base.html with the desired changes.

    Ex:

    templates/
      base.html
      index.html (extends "base.html")
      accounts/
        base.html (extends "base.html")
        affiliate_base.html (extends "base.html")
        my_account.html (extends "accounts/base.html")
        affiliate_dashboard.html (extends "accounts/affiliate_base.html")
        vips/
          base.html (extend "accounts/base.html")
          vip_lounge.html (extends "accounts/vips/base.html")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a django template - one that is normally loaded via a standard
Say I have an integer value that I output to a django template say
I have some french letters (é, è, à...) in a django template but when
I have a django view that I want to return an Excel file. The
say I have the following list that I provide to a django template stuff=
I am new to the Django web framework. I have a template that displays
I have a django form that I'm outputing no problem. My question is with
I have a template that includes several tables. I want to use a sub-template
Hello I'm a Django Beginner. I have a calendar that I want to be
I have an HTML django template page that is both RTL and LTR (depends

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.