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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:40:25+00:00 2026-05-23T15:40:25+00:00

How can I programmatically change sections of a Django template on the fly? Given

  • 0

How can I programmatically change sections of a Django template on the fly?

Given this template:

{% for it in itemlist_1 %}
{{it.unique_display_function_1}}
{%endfor%}

{% for it in itemlist_2 %}
{{it.unique_display_function_2}}
{{it.unique_display_function_2a}}
{{it.unique_display_function_2b}}
{%endfor%}

...

{% for it in itemlist_n %}
{{it.unique_display_function_n}}
{{it.unique_display_function_n_sub_x}}
{{it.unique_display_function_n_sub_xyz}}
{%endfor%}


How could I build a generic Django template so that every time this template is rendered external settings determine what order the itemlists are rendered in the template?

So the list of n sections can appear in any order according to some external settings.

NOTE: Updated to show that each section of the template has a lot of sub-parts and is actually quite long.

  • 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-23T15:40:26+00:00Added an answer on May 23, 2026 at 3:40 pm

    I’d suggest creating a list of the section names in the view corresponding to the order that the user specifies.

    def view(request):
        # this list can also be built dynamically based on user preferences
        item_list = ["section_one.html", "section_two.html", "section_three.html"]
        return render_to_response('main_template.html', RequestContext(request, locals()))
    

    Then in the template you can render each section as a sub-template like below, where the sub-templates are named a “NAME.html” format:

    {%for item in item_list%}
        {% include item %}
    

    Here’s a reference for the include tag: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

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

Sidebar

Related Questions

I have this MenuBar control in Flex 3. How can I programmatically change the
How can I programmatically change my browser's default home page with C#?
How can I change the Hibernate logging level programmatically?
I'm looking for a way to programmatically change navigator.userAgent on the fly. In my
Is there a way I can programmatically change the IBAction of a UIButton? I
How can I programmatically change IIS application pools' settings and properties (for example: the
How can I change an application setting within a web.copnfig programmatically with C# (from
Is there a way I can programmatically change the <endpoint address=... /> value of
How can I programmatically change the back color of a single cell in a
Can I programatically change the quality of a PDF? I have a client that

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.