vandelay
vandelay

Reputation: 2075

Django, send dictionary to template

Is it possible to send a dictionary to a template. And use the django/python magic to work on it client side?

The view function

def index(request):

    context = {
               'users' : users,
               'investments' : { 'one' : 1, 'two' : 2 },
    }
    return render(request, 'index.html', context)

And the html

{% if investments %}
    <h1>{{ investments['one'] }}</h1> #<---- something like that.
{% endif %}

Upvotes: 2

Views: 5256

Answers (1)

Jad S
Jad S

Reputation: 3015

The code below works in Flask-Jinja, and I believe should work in Django:

{% if investments %}
    <h1>{{ investments.one }}</h1>
{% endif %}

Upvotes: 10

Related Questions