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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:38:55+00:00 2026-05-12T21:38:55+00:00

Is there a way to do something like the following in Django templates? {%

  • 0

Is there a way to do something like the following in Django templates?

   {% for hop in hops%}
    <tr>  
      <td>{{ hop.name }}</td>
      <td>{{ hop.mass }}</td>  
      <td>{{ hop."boil time" }}</td>
    </tr>
  {% endfor %}

The hop.”boil time” doesn’t work. The simple solution is rename the key boil_time, but I’m interested in alternatives.

  • 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-12T21:38:56+00:00Added an answer on May 12, 2026 at 9:38 pm

    The best way to get at it is to sneak the property name into another variable, like so:

    {% for key, value in hop.items %}
        {% ifequal key 'boil time' %}
            {{ value }}
        {% endifequal %}
    {% endfor %}
    

    In Django 0.96 (the version used by Google AppEngine) the templating language doesn’t support tuple expansion, so it’s a bit uglier:

    {% for hop in hops %}
        <tr>
            <td>{{ hop.name }}</td>
            <td>{{ hop.mass }}</td>
            <td>
                {% for item in hop.items %}
                    {% ifequal item.0 'boil time' %}
                        {{ item.1 }}
                    {% endifequal %}
                {% endfor %}
            </td>
        </tr>
    {% endfor %}
    

    So, taking your code, we end up with:

    {% for hop in hops %}
        <tr>
            <td>{{ hop.name }}</td>
            <td>{{ hop.mass }}</td>
            <td>
                {% for key, value in hop.items %}
                    {% ifequal key 'boil time' %}
                        {{ value }}
                    {% endifequal %}
                {% endfor %}
            </td>
        </tr>
    {% endfor %}
    

    In Django 0.96 (the version on Google AppEnginge), this becomes:

    {% for hop in hops %}
        <tr>
            <td>{{ hop.name }}</td>
            <td>{{ hop.mass }}</td>
            <td>
                {% for item in hop.items %}
                    {% ifequal item.0 'boil time' %}
                        {{ item.1 }}
                    {% endifequal %}
                {% endfor %}
            </td>
        </tr>
    {% endfor %}
    

    There’s even a wordier way to get at it, using the regroup tag:

    {% regroup hop.items by 'boil time' as bt %}
        {% for item in bt %}
            {% if forloop.first %}
                {% for item2 in item.list %}
                    {% for item3 in item2 %}
                        {% if not forloop.first %}
                            {{ item3 }}
                        {% endif %}
                    {% endfor %}
                {% endfor %}
            {% endif %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any way of accomplishing something like the following: CREATE FUNCTION GetQtyFromID (
Is there any way to get something like the following to work in JavaScript?
Is there a way to do something like the following in C++ template<typename TAnimal>
Is there any way to make something like the following? var template=new Ext.XTemplate( '<tpl
DB: Oracle 11g Is there a way to do something like the following: INSERT
Is there a way to obtain something like a dictionary of all key-value pairs
JSFiddle Is there any way to make something like the X on that link
Is there a way in java to do something like this: void fnc(void Reference_to_other_func());
Is there a better way to do something like this? This is fine but
is there a way in Excel to have a formula that does something like

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.