2010-09-22 113 views

回答

1

如果您有權訪問呈現所需模板的視圖,則可以從數據庫中提取所有的頁面。這裏是一個非常原油和遠從理想的解決方案:

在視圖:

from django.contrib.flatpages.models import Flatpage 

...do your other view stuff 

flatpages = Flatpage.objects.all() 
# You REALLY SHOULD filter() based on other properties of the Flatpages, 
# such as whether or not it requires login to view, or, importantly, 
# which Site it is available on (because not all Flatpages will 
# necessarily be available on the current Site) 

...then pass the flatpages queryset into your view 

在模板:

<ul> 
{% for flatpage in flatpages %} 
    <li><a href="{{flatpage.url}}">{{flatpage.title}}</a></li>  
    {#Note that the page title may not be good link text #} 
{% endfor %} 
</ul> 
1

開發版本使用custom template tag獲得在模板中的所有簡單頁面對象。如果您想立即使用此功能,您應該可以複製source code並將其添加爲自定義標籤。

警告:沒有測試過這個。