python - 为什么我在django html模板里面打印不出来对象的for标签循环
PHPz
PHPz 2017-04-17 11:44:57
0
2
291

为什么我在django html模板里面打印不出来对象的for循环。总是报错啊。但是单独打印对象.属性 是可以的。

<!--打印不出对象,并且总是报错,什么原因?-->
<ul>
{% for k, v in user %}
    <li>{{forloop.counter}}、{{k.v}}</li>
{% endfor %}
</ul>




<!--可以打印出-->
{% if user %}
    <li> {{ user.name }}</li>
{% else %}
    <li> no user </li>
{% endif %}

———————————— 报错的信息是:

TypeError at /blog/index/ 'Person' object is not iterable Request Method: GET Request URL: http://127.0.0.1:8000/blog/index/ Django Version: 1.5.5 Exception Type: TypeError Exception Value:
'Person' object is not iterable

PHPz
PHPz

学习是最好的投资!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!