究竟在一次Request中,Django對數據庫執行了那些查詢和操作呢?呵呵,Django早就為我們想好了這個問題,使用django.core.context_processors.debug模塊即可。
在setting中設置:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.debug", #debug 一次請求調用到多少SQL語句",
)
并設置能看到次debug信息的請求IP:
INTERNAL_IPS = ('127.0.0.1',)
我們就可以在模板中設置一下,即可:
{% endblock %}
{% if sql_queries %}
<h3>SQL excute in this Request</h3>
<!-- debug: show the sql excute in this request -->
{% for query in sql_queries %}<h3>Excute times: {{query.time}}</h3>
<p>
<code>
{{query.sql}}
</code>
</p>
{% endfor %}<!-- debug ends here -->
{% endif %}
以上只會在你設置了TEMPLATE_DEBUG = DEBUG,和請求IP在INTERNAL_IPS設置過,才會顯示。
posted on 2009-04-22 15:20
周銳 閱讀(99)
評論(0) 編輯 收藏 所屬分類:
Python