almost a beginner almost a beginner - 4 months ago 26
HTML Question

Passing Django variable to `<div>` tag

I want to pass a Django variable to a tag. In my case I would like to pass it to the


I want to set the
tag id with the variables returned by my view.

For example (template):

<div class="pool">
{% for pools in poolID %}
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#{{ pools }}">
{{ pools }}
<div id="{{ pools }}" class="collapse">
{% for mem in member %}
{{ mem.first_name }}

{% endfor %}

{% endfor %}

Although I don't think the problem is in the view, then again:

def pool(request):
poolID = Member.objects.order_by().values_list('pool_id').distinct()
member = Member.objects.all()
return render(request, 'app/pool.html', {'poolID':poolID, 'member':member})

When I click the button, it should expand the div, but it doesn't. Meaning the variable syntax is wrong (that's my assumption at least).

The first variable that my view returns is: ('test pool id',)

It should be assigned to target of the button (which includes the hash before the variable) and the id of the div.

Any help or direction would be appreciated,



values_list returns a list of lists, even if you're only selecting a single field per item. You should use flat=True to get a single list.

poolID = Member.objects.order_by().values_list('pool_id', flat=True).distinct()