我有一个django模板页面,看起来像这样。
{% extends "base.html" %} {% load wagtailcore_tags static %} {% block body_class %}template-bidpage{% endblock %} {% block content %} {% for prp in page %} <p>{{ prp }}</p> {% endfor %} {% endblock content %}
但是加载这个页面会给我一个错误 'MyPage' object is not iterable 是的。如何显示我的每个项目 MyPage 反对?
'MyPage' object is not iterable
MyPage
您应该在模型类中编写一个方法以返回属性。
class MyPage(Page): # your fields go here def get_properties(self): # return all properties
然后在你的模板中
{% extends "base.html" %} {% load wagtailcore_tags static %} {% block body_class %}template-bidpage{% endblock %} {% block content %} {% for prp in page.get_properties %} <p>{{ prp }}</p> {% endfor %} {% endblock content %}