1

In python i am passing below context in django template:

{'expr': 'next_expr', 'next_expr': 'value'}

In template, i am trying to print 'value':

{{ {{ expr }} }}

I know above expression wont work but i want to achieve something like this:

{{ {{ expr }} }} ---> {{ next_expr }} ---> 'value'

Is there any method in django inbuilt by which i get 'value'?

Thanks!

Love Sharma
  • 1,981
  • 1
  • 18
  • 37

1 Answers1

1

If I understood correctly and the Python object is passed as tmp variable:

tmp = {'expr': 'next_expr', 'next_expr': 'value'}

you could do that in Jinja2:

{{tmp[tmp['expr']]}}

In Django all I could find is something like this, but I don't think that this is what you want

{% for k, v in tmp.items %} 
  {{k}} - {{v}} |
{% endfor %}
Community
  • 1
  • 1
Lipis
  • 21,388
  • 20
  • 94
  • 121
  • I get TemplateSyntaxError: Could not parse the remainder: '[tmp['expr']]' from 'tmp[tmp['expr']]' when I wrote your exact expression in template. – Love Sharma Oct 16 '12 at 16:11
  • 1
    @LoveSharma Hmm... works nicely in Jinja2.. It should be the same.. http://stackoverflow.com/a/1724201/8418 :( – Lipis Oct 16 '12 at 18:44
  • raising answer... but not exact answer which i am looking and may be its not possible in django. So i implemented custom tag and work fine. Thanks for your effort. :) – Love Sharma Oct 17 '12 at 20:48