那个blog的小程序,今天再运行的时候出错了。看了一下记录:
File “C:\Python27\lib\site-packages\web.py-0.36-py2.7.egg\web\utils.py”, line 908, in da
testr
out = then.strftime(‘%B %e’) # e.g. ‘June 13′
ValueError: Invalid format string
浏览器提示的错误是:
<type ‘exceptions.ValueError’> at /
Invalid format string
Python C:\Python27\lib\site-packages\web.py-0.36-py2.7.egg\web\utils.py in datestr, line 907
Web GET http://localhost:8080/
C:\Python27\lib\site-packages\web.py-0.36-py2.7.egg\web\utils.py in datestr
C:\Python27\lib\site-packages\web.py-0.36-py2.7.egg\web\utils.py in datestr
deltadays = abs(deltaseconds) // oneday
if deltaseconds < 0: deltadays *= -1 # fix for oddity of floor
if deltadays:
if abs(deltadays) < 4:
return agohence(deltadays, 'day')
out = then.strftime('%B %e') # e.g. 'June 13' ...
if then.year != now.year or deltadays < 0:
out += ', %s' % then.year
return out
if int(deltaseconds):
if abs(deltaseconds) > (60 * 60):
▼ Local vars
Variable Value
agohence
<function agohence at 0x01495FB0>
delta datetime.timedelta(5, 1347, 859000)
deltadays 5
deltaseconds 433347
now datetime.datetime(2012, 6, 4, 22, 6, 4, 859000)
oneday 86400
then datetime.datetime(2012, 5, 30, 21, 43, 37)
templates\index.html in __template__
from $datestr(post.posted_on) ...
问题是出在了strftime函数上。查了一下这个函数,官方网站8.1.7. strftime() and strptime() Behavior上不支持%e这个参数。但是以前的却支持Python time strftime() Function,这里还有一个讨论的Why %e not in time.strftime directives? 。
%d Day of the month as a decimal number [01,31].
%e – day of the month (1 to 31)
所以,根据Python的2.7.3版本,修改web\utils.py”, line 908,%e为%d即可。
#out = then.strftime('%B %e') # e.g. 'June 13'
# from http://docs.python.org/library/datetime.html#strftime-strptime-behavior
# no %e, use %d instead of %e. ian#2012-6-5
out = then.strftime('%B %d') # e.g. 'June 13'
本文探讨了在使用web.py框架时遇到的一个日期格式化问题,即strftime函数不支持%e参数,而改为使用%d参数解决了此问题,并提供了修改建议。
3万+

被折叠的 条评论
为什么被折叠?



