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 GET http://0.0.0.0:8080/
> 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 GET http://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.
> > 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
'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
<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>
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 <miles.gro...@gmail.com> wrote: > > I suggest sticking with sqlite3 for development/testing purposes. > > Easy to set up. Easy to tear down.