现在我正在尝试在我的模板中使用切片但是它显示了这个错误: -
TemplateSyntaxError at /post/
'for' statements should use the format 'for x in y': for item in user_basic_info |slice:"2"
{%for item in user_basic_info |slice:"2"%}
<li>
<div class="userimg_sec">
<div class="userimg">
<img src="{{ item.profileImage }}">
</div>
</div>
<div class="userdetails">
<p class="username">{{ item.name }}</p>
<p class="usernickname">@{{ item.username }}, <span>teacher</span></p>
</div>
</li>
{% endfor %}
答案 0 :(得分:2)
你需要删除空格:
{% for item in user_basic_info|slice:"2" %}
<!-- remove space ^^-->
答案 1 :(得分:2)