This bug held my night

Even though wrote my own view for returning a list of relevant months, having posts, it never showed up correct.

Digging in deep, found that <utc> stamped datetime objects in python when passed through django’s templating system ends up with a wrong result.

>>> date_list[6]
datetime.datetime(2012, 6, 1, 0, 0, tzinfo= <utc>)

The month indicates June, but when rendered with a template, the month is decreased by one i.e ‘may’

>>> t = Template(“The month is {{ month|date:’m’ }} “)
>>> c = Context({“month”: date_list[6]})
>>> t.render(c)
u’The month is 05

whereas the real value is

>>> date_list[6].month

Made notification with Stackoverflow to find out whether it’s really a bug. or I myself am missing out something.
Worked it out by converting the datetime object into a date object and then passing to the template.
That costed a saturday night sleep!



Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s