我在我的網站的單獨頁面上構建了以前的存檔。不過,Django這次似乎不想與我合作。在Django實施每年一次的月度存檔
class IndexView(ArchiveIndexView):
template_name = 'cms/blog_base.html'
date_field = 'pub_date'
latest = '20'
model = Entry
In template {% for year in date_list %} {{ year|date:"Y" }} gives me a date relating to none of my entries. {% for entry in object_list % } {{ entry.pub_date|date:"Y" }} obviously outputs the correct date for the entry but as the entries grow I can only imagine it will continue to duplicate the years and months.
那麼我做錯了什麼?爲了將日期與我的條目集合關聯起來,我需要在ArchiveIndexView和模板標籤中做些什麼?過去,它們在單獨的頁面上,因此被URL conf中的正則表達式過濾。我看到的一個解決方案是使用一些原始SQL創建自定義管理器,這就是我所看到的?如果是的話,我會重新考慮這一切。預先感謝社區。
更新:例如:我在我的主頁上想要的東西與本頁上的內容類似https://unweb.me/blog/monthly-archives-on-Django我現在也在考慮嘗試他們的解決方案,因爲它看起來像一個不錯的UI/UX。但是,我是一個簡單的人,如果有一個簡單的路線,我會很樂意。
這包括所有年/月,而不管帖子。你知道如何讓它只輸出有年份/月份的文章嗎? –
我不得不''進口時間'和'進口日曆'使這項工作。 – woodbine