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

为什么我在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

学习是最好的投资!

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!