Hi,
I had the same problem. This is why it is not working...
>>> import datetime
>>> import web
>>>
>>> datetime.datetime.utcnow() # Returns a datetime object
datetime.datetime(2012, 9, 27, 19, 39, 5, 350000)
>>>
>>> datetime_obj = datetime.datetime.utcnow()
>>>
>>> str(datetime_obj) # What we get back when we query our database
'2012-09-27 19:39:30.756000'
>>>
>>> help(web.datestr) # What datestr expects is a datetime object
Help on function datestr in module web.utils:
datestr(then, now=None)
Converts a (UTC)
datetime object to a nice string representation.
...
So the code as is will never work since we are passing web.datestr a string in index.html and view.html. The answer to the problem is to pass it the datetime object it is expecting. One solution (mine...) is as follows.
Edit your
blog.py and remove datestr from t_globals
t_globals = {
'transform_datestr': model.transform_datestr
}
Next edit your
model.py and add the following function
def transform_datestr(posted_on):
datetime_obj = datetime.datetime.strptime(posted_on,'%Y-%m-%d %H:%M:%S.%f')
return web.datestr(datetime_obj)
Lastly edit
index.html and
view.html and replace the call to datestr with the following
view.html $def with (post)
<h1>$post.title</h1>
<br>
$transform_datestr(post.posted_on)<br/>
$post.content
index.html $def with (posts)
<h1>Blog posts</h1>
<ul>
$for post in posts:
<li>
<a href="/view/$
post.id">$post.title</a>
from
$transform_datestr(post.posted_on) <a href="/edit/$
post.id">Edit</a>
</li>
</ul>
Hope that works for you!