开发者

Manually rendering django template with date filter

I've got the template to render manually, but not the dates with a filter. Is there a way of doing this without formatting the dates before I put them in the context?

Here is the code:

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 gives the output:

This is to notify you that you are booked on the course Course 1 t开发者_如何学JAVAhat starts on  at  and is being held at Venue for Course 1.

Why don't the dates show up?


Looks like a simple typo between start_date vs. 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜