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!
On Wednesday, July 14, 2010 2:13:23 PM UTC-7, handloomweaver wrote:
>
> I've been trying to get the blog example working but getting an error
> under sqlite3. See above. Any thoughts?
>
> On Jul 14, 9:04 pm, m g <[email protected]> wrote:
> > I suggest sticking with sqlite3 for development/testing purposes.
> > Easy to set up. Easy to tear down.
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/webpy/-/p0NmnLODAz8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.