2017-09-06 41 views
0

我已經創建了一個視圖,它將一個項目的兩個日期傳遞給html模板。我同時獲得在HTML模板的日期,如下圖所示:在Django模板中的三角洲日期

{% for item in items %} 
{{ item.form_date }} 
{{ item.to_date }} 
     # I need the difference between the dates here.... 
{% endfor %} 

我不想回差數據形成的觀點,但希望在這裏看到的日期的增量在HTML中。我該怎麼做?

回答

2

你可以嘗試timesince

{{ item.form_date|timesince:item.to_date }} 
+0

我都試過,但它顯示錯誤。我也用to_date替換了comment_date,但仍顯示相同的錯誤 –

+0

對不起,我修復了錯字錯誤,試試吧 –

+0

謝謝。有效。但它顯示'1周,1天'。我可以更改天數的格式嗎?輸出不能是'8天'嗎? –