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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:49:41+00:00 2026-05-27T11:49:41+00:00

I am looking for way to clean up a template in django. A simple

  • 0

I am looking for way to clean up a template in django. A simple solution would be to break this up into multiple templates, but we do not want to do that.

We basically have the following

{%if data.some_state %}
    Display some markup
{% else %}
   {%if data.some_state_2 %}
       State 2 different html view 
   {% else %}
        {%if data.process_data %}
           Display some list of data
        {% else %}
           No Data to display!
       {% endif %} <!-- if data.process_data-->
   {% endif %} <!-- if data.some_state_2 -->
{% endif %} <!-- if data.some_state -->

So that is extremely confusing and hard to read. If I could do this in a “function” i would use if/else if or returns.

Is there a way in template language to do something like (stop_processing_template would tell the template we are done… ):

{%if data.some_state %}
    Display some markup
{% endif %}
{% django_stop_processing_template %}


{%if data.some_state_2 %}
       State 2 different view
{% endif %}
{% django_stop_processing_template %}

{%if data.process_data %}
           Display some list of data
{% endif %}
{% django_stop_processing_template %}

 No data provided !
  • 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-27T11:49:41+00:00Added an answer on May 27, 2026 at 11:49 am

    You could use jinaj2 for templating that view (or the whole project), it supports if/elif/else branching:

    {% if data.some_state %}
        Display some markup
    {% elif data.some_state_2 %}
        State 2 different view
    {% elif data.process_data %}
        Display some list of data
    {% endif %}
    

    There are a couple different packages which it easy use jinja2 in a django project, I’ve used both coffin and djinja for this.

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

Sidebar

Related Questions

I need to generate this simple looking XML, looking for a clean way to
I am looking for a neat/clean way to store a list of strings into
I'm looking for a fast, clean, pythonic way to divide a list into exactly
hey I'm looking for are clean solution to this problem: i start the loop
I'm looking for clean way to break my current habit of using print commands
I'm looking for a clean way to implement the infamous select all checkbox, but
I am looking for a clean way to check if a registry key exists.
I'm looking for a clean way to import one git repository from another, where
I was looking for a reliable, clean way to do advanced runtime reports for
I'm looking for a way to automatically do some clean up tasks when the

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.