Reputation: 3663
I have a Django template page that looks something like this.
{% 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 %}
But loading this page up gives me the error 'MyPage' object is not iterable
. How do I display each proeprty of my MyPage
object?
Upvotes: 0
Views: 413
Reputation: 580
You should write a method inside your model class to return the properties.
class MyPage(Page):
# your fields go here
def get_properties(self):
# return all properties
Then in your templates
{% 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 %}
Upvotes: 1