2013-11-28 34 views

回答

0

佔位情況下有兩種方法,可以幫助這一點:

get_pluginsget_plugins_list

從你可以做以下的模板:

{% with total_plugins=placeholder_instance.get_plugins.count %} 
<p>There's {{ total_plugins }} here !!!</p> 
{% endwith %} 

OR

{% with total_plugins=placeholder_instance.get_plugins_list|length %} 
<p>There's {{ total_plugins }} here !!!</p> 
{% endwith %} 

區別在於get_plugins返回的查詢集和get_plugins_list所以如果你打算遍歷這些插件,我會建議get_plugins_list所以你只打了DB一次返回一個列表,否則get_plugins更如果你只是想要一個計數,效率很高

+0

我該如何實施?我錯過了一些背景。我試過了:{%with total_plugins = placeholder_instance.get_plugins.count%} {%placeholder gallery%}

這裏有{{total_plugins}}!

{%endwith%} – niels

+0

你要在哪裏實現這個?這意味着你是從插件模板執行此操作還是隻使用普通視圖呈現的普通模板? – Paulo

+0

在正常(Django)模板中。 – niels

相關問題