> > My name is AL and I'm completely new to programming and trying to
> > teach myself Programming & Python at the ripe old age of 35. I
> > downloaded the web.py basic blog app and used SQLite3 as my db
> > db = web.database(dbn='sqlite', db='blog.db')
> > I am getting what I know is probably an embarrassingly easy python
> > error but I can't find the solution. The error is:
> > <type 'exceptions.TypeError'> at /
> > unsupported operand type(s) for -: 'datetime.datetime' and 'unicode'
> > Python /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> > site-packages/web/utils.py in datestr, line 704
> > Web GEThttp://0.0.0.0:8080/
> > Can anyone help?
> Looks like problem with sqlite driver.
> Can you check if you have sqlite3 or pysqlite2 modules available? You
> can test that by running "import sqlite3" and "import pysqlite2" from
> python prompt.
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
>>> 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