<p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>

<pre><code>Object Result:
    Items = [item1,item2]
    Users = [{name='username',item1=3,item2=4},..]
</code></pre>

<p>The Django template is:</p>

<pre><code>&lt;table&gt;
&lt;tr align="center"&gt;
    &lt;th&gt;user&lt;/th&gt;
    {% for item in result.items %}
        &lt;th&gt;{{item}}&lt;/th&gt;
    {% endfor %}
&lt;/tr&gt;

{% for user in result.users %}
    &lt;tr align="center"&gt; 
        &lt;td&gt;{{user.name}}&lt;/td&gt;
        {% for item in result.items %}
            &lt;td&gt;{{ user.item }}&lt;/td&gt;
        {% endfor %}
    &lt;/tr&gt;
{% endfor %}
&lt;/table&gt;
</code></pre>

<p>Now the <a href="http://www.djangoproject.com/documentation/0.96/templates/#variables" rel="noreferrer">Django documention</a> states that when it sees a <strong>.</strong> in variables<br>
It tries several things to get the data, one of which is dictionary lookup which is exactly what I want but doesn't seem to happen...</p>

[{'answer_id': 35978, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m assuming that the part the doesn\'t work is <code>{{ user.item }}</code>.</p>\n\n<p>Django will be trying a dictionary lookup, but using the string <code>"item"</code> and not the value of the <code>item</code> loop variable.  Django did the same thing when it resolved <code>{{ user.name  }}</code> to the <code>name</code> attribute of the <code>user</code> object, rather than looking for a variable called <code>name</code>.</p>\n\n<p>I think you will need to do some preprocessing of the data in your view before you render it in your template.</p>\n'}, {'answer_id': 37190, 'author': 'Nic Wise', 'author_id': 2947, 'author_profile': 'https://Stackoverflow.com/users/2947', 'pm_score': 0, 'selected': False, 'text': "<p>shouldn't this:</p>\n\n<pre><code>{{ user.item }}\n</code></pre>\n\n<p>be this?</p>\n\n<pre><code>{{ item }}\n</code></pre>\n\n<p>there is no user object in the context within that loop....?</p>\n"}, {'answer_id': 50425, 'author': 'Yon', 'author_id': 3117, 'author_profile': 'https://Stackoverflow.com/users/3117', 'pm_score': 6, 'selected': True, 'text': '<p>I found a "nicer"/"better" solution for getting variables inside\nIts not the nicest way, but it works.</p>\n\n<p>You install a custom filter into django which gets the key of your dict as a parameter</p>\n\n<p>To make it work in google app-engine you need to add a file to your main directory,\nI called mine <em>django_hack.py</em> which contains this little piece of code</p>\n\n<pre><code>from google.appengine.ext import webapp\n\nregister = webapp.template.create_template_register()\n\ndef hash(h,key):\n    if key in h:\n        return h[key]\n    else:\n        return None\n\nregister.filter(hash)\n</code></pre>\n\n<p>Now that we have this file, all we need to do is tell the app-engine to use it...\nwe do that by adding this little line to your main file</p>\n\n<pre><code>webapp.template.register_template_library(\'django_hack\')\n</code></pre>\n\n<p>and in your template view add this template instead of the usual code</p>\n\n<pre><code>{{ user|hash:item }}\n</code></pre>\n\n<p>And its should work perfectly =)</p>\n'}, {'answer_id': 1278623, 'author': 'Brandon Henry', 'author_id': 112620, 'author_profile': 'https://Stackoverflow.com/users/112620', 'pm_score': 2, 'selected': False, 'text': '<p>@Dave Webb (i haven\'t been rated high enough to comment yet)</p>\n\n<p>The dot lookups can be summarized like this: when the template system encounters a dot in a variable name, it tries the following lookups, in this order:</p>\n\n<pre><code>* Dictionary lookup (e.e., foo["bar"])\n* Attribute lookup (e.g., foo.bar)\n* Method call (e.g., foo.bar())\n* List-index lookup (e.g., foo[bar])\n</code></pre>\n\n<p>The system uses the first lookup type that works. It’s short-circuit logic.</p>\n'}, {'answer_id': 3125956, 'author': 'Niall Farrington', 'author_id': 288710, 'author_profile': 'https://Stackoverflow.com/users/288710', 'pm_score': 2, 'selected': False, 'text': "<p>As a replacement for k,v in user.items on Google App Engine using django templates where user = {'a':1, 'b', 2, 'c', 3}</p>\n\n<pre><code>{% for pair in user.items %}\n   {% for keyval in pair %} {{ keyval }}{% endfor %}&lt;br&gt;\n{% endfor %}\n</code></pre>\n\n<p>a 1<br>\nb 2<br>\nc 3<br></p>\n\n<p>pair = (key, value) for each dictionary item.</p>\n"}, {'answer_id': 3466349, 'author': 'Martyn', 'author_id': 418239, 'author_profile': 'https://Stackoverflow.com/users/418239', 'pm_score': 3, 'selected': False, 'text': "<p>Or you can use the default django system which is used to resolve attributes in tempaltes like this : </p>\n\n<pre><code>from django.template import Variable, VariableDoesNotExist\n@register.filter\ndef hash(object, attr):\n    pseudo_context = { 'object' : object }\n    try:\n        value = Variable('object.%s' % attr).resolve(pseudo_context)\n    except VariableDoesNotExist:\n        value = None\nreturn value\n</code></pre>\n\n<p>That just works</p>\n\n<p>in your template :</p>\n\n<pre><code>{{ user|hash:item }}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/35948', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3117/']