Reputation: 601
I want to pass value of variable from django view to template.
view:
def countsnippet(request):
checkins = Attendee.objects.filter(checkin=True).count()
return render( request, 'search/countsnippet.html', {'inft': checkins} )
Template snippet:
<div class="row" >
{% block content %}
<p>INFT : {% 'inft' %}</p>
{% endblock %}
</div>
I want to pass checkins value to template, but using above approach is giving me error.
Upvotes: 1
Views: 144
Reputation: 476547
You render a "variable" by placing it between double curly brackets ({{ }}
), like:
<div class="row" >
{% block content %}
<p>INFT : {{ inft }}</p>
{% endblock %}
</div>
The variable name is not surrounded by quotes, and you can treat it thus like an identifier.
You can furthermore use a sequence of identifiers separated by dots (like {{ foo.bar }}
) to access the bar
attribute/element of foo
.
Furthermore Django templates allow extra features like template filters, etc. See the Django documentation on the template language for an in-depth article.
Upvotes: 1