Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Template: how to dump object on page in full

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>
like image 632
Prometheus Avatar asked Dec 25 '12 00:12

Prometheus


2 Answers

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 %}
like image 62
Bryce Avatar answered Sep 30 '22 06:09

Bryce


Stick this at the top:

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

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

like image 20
John Mee Avatar answered Sep 30 '22 04:09

John Mee