0
저는 C#으로 코딩하는 데 익숙합니다.Django - 장고 템플릿의 객체 수를 제한합니다.
int start_index = 4;
List<int> list = { ... }
for(int i = start_index;i < 10;i++){
list[i].dosomething();
}
이 내가 장고
이 코드는 분명히 작동하지 않습니다{% with 0 as starting_index %}
{% for comment in comments %}
<!--set a variable to limit the amount of comment on a page-->
{% with forloop.counter as index %}
{% if index < 3 %}
<div class="comment_body">
<div class="content_block">
<p>{{comments[index]}}</p>
</div>
</div>
{% endif %}
{% endwith %}
{% endfor %}
{% endwith %}
에서 시도하는 방법입니다 : 내가 좋아하는 뭔가를 Python을 사용하고 싶습니다. 아무도이 문제를 도와 줄 수 있습니까? 미리 감사드립니다.
템플릿에서이 작업을 수행하는 대신보기에서이 작업을 수행하는 것이 좋습니다. 말이 돼? – rajkris
@ RajKris 당신 말이 맞아요, 우리가보기, 하하를 사용할 수 있다는 것을 잊지 마십시오 –
그것이 도움이 되었길 바랍니다! 건배. – rajkris