这是我的代码:Python的datetime.strptime只适用于开发环境
for i in report:
reports.append({
'total':i['vends__sum'],
'date':datetime.strptime(i['month'], "%Y-%m-%d %H:%M:%S")
})
这个工作对我的OSX的开发环境(的virtualenv ENV的Django 1.5)
但我的生产服务器上(Ubuntu的12.04的virtualenv Django的1.5),它并没有与此错误的工作:
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:
must be string, not datetime.datetime
Exception Location: /var/www/webapps/cirostats/products/templatetags/product_tags.py in show_main_chart, line 41
41号线是
'date':datetime.strptime(i['month'], "%Y-%m-%d %H:%M:%S")
我弄不明白为什么在一个环境而不是其他环境中工作?谁在这里错了,开发人员或产品?
Prod : Python 2.7.3
Dev: Python 2.7.1
更多:
这是报告的制作过程:
truncate_date = connection.ops.date_trunc_sql('month','timestamp')
qs = objects.extra({'month':truncate_date})
report = qs.values('month').annotate(Sum('vends')).order_by('month')
嗯,我是这样的:{'vends__sum':328,'month':u'2013-06-01 00:00:00'} – Harry
没有生产,不是这样。 –