Django Template: how to dump object on page in full

Question:

The following template is not outputting anything despite there being data.

My question is… is there I was I can dump out into the template the content of ‘points’ object just so I can see what is in it?

template.py

 <h3>{% trans "Points" %}</h3>

    {% if points %}
        <p>{% trans "Total Points" %}: {{ points.Points }}</p>


        <table>
            <thead>
            <tr>
                <th>{% trans "Transaction" %}</th>
                <th>{% trans "Status" %}</th>
                <th>{% trans "Points" %}</th>
            </tr>
            </thead>
            <tbody>
            {% for item in points.Points_items.all %}
                <tr>
                    <td>{{ item.transaction_description }}</td>
                    <td>{{ item.get_status_display }}</td>
                    <td>{{ item.points }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
Asked By: Prometheus

||

Answers:

Stick this at the top:

<h1>|{{ points }}|</h1>

If there’s nothing between the | then it’s empty.

Answered By: John Mee

I use a custom tag for this:

# Custom tag for diagnostics
@register.simple_tag()
def debug_object_dump(var):
    return vars(var)

And

{% load extra_tags %}
...
{% for thing in things %}
  <pre>{% debug_object_dump thing %}</pre>
{% endfor %}
Answered By: Bryce

You can use the {% debug %}, it dumps a lot of information, usefull to debug those situations.

More fine-grained there’s also a pprint filter: {{ points.Points|pprint }}

Answered By: Julien Palard
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.