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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:33:12+00:00 2026-05-11T12:33:12+00:00

I found a link to have a ‘switch’ tag in Django templates, but I

  • 0

I found a link to have a ‘switch’ tag in Django templates, but I was wondering if this can be somehow achieved without it. Using only the stuff which comes with Django? Basically is there other way then using multiple ‘if’ or ‘ifequal’ statements?

  • 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. 2026-05-11T12:33:13+00:00Added an answer on May 11, 2026 at 12:33 pm

    Unfortunately, this is not possible with the default Django template engine. You’ll have to write something ugly like this to emulate a switch.

    {% if a %}     {{ a }} {% else %}     {% if b %}         {{ b }}     {% else %}         {% if c %}             {{ c }}         {% else %}             {{ default }}         {% endif %}     {% endif %} {% endif %} 

    or if only one if condition can be true and you don’t need a default.

    {% if a %} {{ a }} {% endif %} {% if b %} {{ b }} {% endif %} {% if c %} {{ c }} {% endif %} 

    Usually, when the template engine is not powerful enough to accomplish what you want this is a sign that the code should be moved into Django view instead of in the template. For example:

    # Django view if a:   val = a elif b:   val = b elif c:   val = c else:   val = default  # Template {{ val }} 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
i have a problem using the Catch Clipboard Events code found on this link
I have found this link http://smartclient.codeplex.com/ which has some updates for vs 2010 ....
I found a link here on Stack that explains how to do this, but
Does Javascript supports Sets(list with unique objects only) ? I have found this link
I want a filter for my ListView in Android. I have found this link
I have found articles saying this is possible, but what are the issues? Is
i have found the link in this link @RoIT suggested that Search markerImage in
I found this link WPF_Example , but it is written in WPF. I am
I have found this link: Detect Antivirus on Windows using C# However 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.