2010-11-30 62 views
0

我已經有了手動呈現模板,但沒有過濾器的日期。有沒有這樣做的方式沒有格式化日期之前,我把它們放在上下文中?用日期過濾器手動呈現Django模板

下面是代碼:

t= This is to notify you that you are booked on the course {{title}} that starts on {{start_date|date:"F j, Y"}} at {{start|time}} and is being held at {{venue}}. 

c = {'startdate': datetime.datetime(2010, 12, 1, 9, 0), 'enddate': datetime.datetime(2010, 12, 1, 12, 0), 'has_cpd': False, 'title': 'Course 1', 'closes': None, 'creator': 1L, 'venue': 'Venue for Course 1', 'summary': 'Course 1 Summary', 'tags': '', 'attachment': <FieldFile: None>, 'organiser': 3L, 'id': 1L, 'opens': datetime.datetime(2010, 11, 30, 20, 1, 50, 951490), 'venue_map': None} 

t.render(c) 

這使輸出:

This is to notify you that you are booked on the course Course 1 that starts on at and is being held at Venue for Course 1. 

爲什麼不日期顯示?

回答

1

看起來像是start_date與startdate之間的簡單拼寫錯誤。

In [18]: t= Template("""This is to notify you that you are booked on the course {{title}} that starts on {{startdate|date:"F j, Y"}} at {{start|time}} and is being held at {{venue}}.""") 
In [19]: t.render(c)Out[19]: u'This is to notify you that you are booked on the course Course 1 that starts on December 1, 2010 at and is being held at Venue for Course 1.' 
+0

糟糕 - 謝謝! – PhoebeB 2010-11-30 20:21:18