serverman
serverman

Reputation: 1314

Rendering django template with a json object

Consider a json object: { "config": {"key1": "value"} }

Within the html template (which is rendered using the above json as the context, how do access the "key1" directly? Conceptually I want to do the following:

<html>
<body>
The config value is {{config['key1']}}
</body>
</html>

but, obviously that does not work.

In other words how do I access any element of a dictionary object of the context within a template?

Upvotes: 0

Views: 1841

Answers (2)

serverman
serverman

Reputation: 1314

The issue (as pointed out by Tomasz Zielinski in a comment) that django supports dictionary objects directly - not json.

Upvotes: 0

Reto Aebersold
Reto Aebersold

Reputation: 16624

Use the dot notation:

<html>
    <body>
        The config value is {{ config.key1 }}
    </body>
</html>

Upvotes: 2

Related Questions