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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:29:44+00:00 2026-05-13T08:29:44+00:00

According to The Django Book , Django’s templating system supports nested dot lookups: Dot

  • 0

According to The Django Book, Django’s templating system supports nested dot lookups:

Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary lookup (person[‘name’]), then a method call (upper()): ‘{{ person.name.upper }} is {{ person.age }} years old.’

Are there goblins with this approach not widely covered in the documentation? I am having problems with nested dot lookups — here’s a minimal example:

views.py:

test = [{'foo': [1, 2, 3], 'bar': [4, 5, 6]}, {'baz': [7, 8, 9]}]
ndx = 'bar'
t = loader.get_template('meh.html')
c = Context({'test': test,
             'ndx': ndx,})
return HttpResponse(t.render(c))

meh.html template:

<pre>
   {{ test }}
   {{ test.0 }}
   {{ test.0.ndx }}
</pre>

Resulting HTML:

<pre>
[{'foo': [1, 2, 3], 'bar': [4, 5, 6]}, {'baz': [7, 8, 9]}]
 {'foo': [1, 2, 3], 'bar': [4, 5, 6]}

</pre>

The nested lookup of a dictionary key within a list element returns nothing, when I expect [4, 5, 6].

J.J.

  • 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-13T08:29:44+00:00Added an answer on May 13, 2026 at 8:29 am

    I think the problem is that you are expecting ndx to be evaluated when that simply never happens. Have you tried this:

    {{ test.0.bar }}
    

    I think that will do what you’re looking for.

    Are there goblins with this approach…?

    Sort of, but they aren’t the ones you’re talking about, and I don’t think it’s because of nesting, or at least, it doesn’t get worse after you get one level deep. What I mean by this is that all lookup parameters are literals. There’s no way to change that. So while you might be able to develop custom template tags and pass them literals or variables to evaluate, you’re really out of luck if you want to directly access some member of a variable based on the evaluated value of another value. (You could possibly write a template tag for this, but it won’t work in all desired situations and is possibly more complicated than it’s worth.)

    For whatever it’s worth, this looks like a pretty intentional facet of the templating language. I invite you to consider how the accessor should know whether {{ foo.bar }} should be read as foo[bar] or foo['bar']. It doesn’t seem possible to make a meaningful judgment without complicating the syntax and that’s something that django’s template design is adamant about avoiding.

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

Sidebar

Related Questions

According to this thread on the django-developers list, I can't pass the constant False
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
According to this section in the Django docs I should use {% blocktrans %}
Django 1.2 has brought in some changes in the syndication framework. According to this
I'm using django.views.generic.list_detail.object_detail. According to the documentation the view takes the variable object_id. To
I'm learning django with this excellent book Practical Django Projects. I was able to
According to the Django testing docs, the Django client Response object contains 'templates', which
According to the Documentation using the django.views.static.server() function is: inefficient and insecure. I understand
According to the Hyde website , Hyde is based on the Django template engine.

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.