#django #twitter-bootstrap #collapse
#django #twitter-bootstrap
Вопрос:
Если я использую {{forloop.count}}
or {{object.pk}}
для рендеринга ID и href, свертывание не работает, но если я жестко закодирую ID и href, все будет работать так, как должно. В чем здесь может быть проблема?
Мой шаблон:
{% for Entry in object_list %}
<li style="list-style-type: none; margin-bottom: 2px;">
<a data-toggle="collapse" href="#{{ Entry.pk }}"> </a>
<big><a style="text-decoration: none;" target="_blank" href="{{ Entry.url }}">{{ Entry.title }}</a></big> <small style="color: tomato;">[{{ Entry.tickers|upper }}] </small><small style="color: silver;">[{{ Entry.domain }}] <i>{{ Entry.timestamp|shortnaturaltime }}</i> </small>
<div class="collapse" id="{{ Entry.pk }}">{{ Entry.summary }}</div></li>
{% empty %}
<li>No listings yet.</li>
{% endfor %}
HTML:
<li style="list-style-type: none; margin-bottom: 2px;">
<a data-toggle="collapse" href="#666743"> </a>
<big><a style="text-decoration: none;" target="_blank" href="http://title.io">Title</a></big> <small style="color: tomato;">[TAG] </small><small style="color: silver;">[title.io] <i>4h</i> </small>
<div class="collapse" id="666743">La marca y el logo que en...</div></li>
Это работает нормально:
<a data-toggle="collapse" href="#collapse"> </a>
<div class="collapse" id="collapse">Craft beer labore wes anderson cred nesciunt sapiente ea proident.</div>
Ответ №1:
Рабочее решение с помощью кнопки:
<button type="button" data-toggle="collapse" data-target="#{{ Entry.pk }}" aria-expanded="false" aria-controls="{{ Entry.pk }}"> </button>