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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:00:31+00:00 2026-05-11T14:00:31+00:00

I am trying to compare the length of a dictionary inside a django template

  • 0

I am trying to compare the length of a dictionary inside a django template

For example, I would like to know the correct syntax to do the following:

    {% if error_messages %}         <div class='error'>             {% if length(error_messages) > 1 %}                 Please fix the following errors:                 <div class='erroritem'>                     {% for key, value in error_messages.items %}                         <br>{{ value }}                     {% endfor %}                 </div>              {% else %}                     {% for key, value in error_messages.items %}                         {{ value }}                     {% endfor %}             {% endif %}         </div>     {% endif %} 
  • 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-11T14:00:32+00:00Added an answer on May 11, 2026 at 2:00 pm

    You could do this, using the length filter and the ifequal tag:

    {% if error_messages %}     <div class='error'>         {% ifequal error_messages|length 1 %}             error_messages[0]         {% else %}             Please fix the following errors:             <div class='erroritem'>             {% for key, value in error_messages.items %}                 <br>{{ value }}             {% endfor %}             </div>         {% endifequal %}     </div> {% endif %} 

    Anything else will have to go down the path of custom tags and filters.

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

Sidebar

Related Questions

Im trying to compare the values of two edittext boxes. What i would like
I am trying to compare the value of 2 instances of x inside an
I am trying to compare the lists. Given function(List1,List2) and List1 has length N
I am trying to compare a string and a char like below : char
I'm trying to compare two lists by length and set the output to true
Trying to compare and print only members with Inactive status. The problem is that
Im trying to compare these two chars but on win 32 Visual Studio 2008:
I am trying to compare the performance of several Javascript libraries. Although measuring transaction
I am trying to compare two text files and output the first string in
I am trying to compare two strings in a simple shell script. I was

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.