2012-12-25 58 views
2

儘管存在數據,但以下模板不會輸出任何內容。Django模板:如何在頁面上完全轉儲對象

我的問題是...在那裏我是我可以傾銷到模板的'點'對象的內容,所以我可以看到它是什麼?

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> 

回答

5

棒這個頂部:

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

如果有什麼的|那麼它是空的。

+0

我剛剛得到這個[<點數:Points對象>,<點數:Points對象>]這是否意味着其空然後? – Prometheus

+3

沒什麼?或者其他的東西?如果你想讓它逐項列出點的內容,可以創建一個'__str__'或'__unicode__'方法。 –

+0

@JohnMee Oooh,有人有態度問題。 – igneosaur

4

我使用自定義標籤此:

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

而且

{% load extra_tags %} 
... 
{% for thing in things %} 
    <pre>{% debug_object_dump thing %}</pre> 
{% endfor %} 
相關問題