Reputation: 2075
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
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