2016-10-02 61 views
0

如果我使用{{forloop.count}}{{object.pk}}进行ID和href渲染,collapse不起作用,但是如果我硬编码ID和href,它就像它应该那样工作。这里可能是什么问题?Django + Bootstrap + Collapse + Item.PK =问题

我的模板:

{% 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> 

回答

0

工作液使用按钮:

<button type="button" data-toggle="collapse" data-target="#{{ Entry.pk }}" aria-expanded="false" aria-controls="{{ Entry.pk }}">+</button>