Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Embarrassing Newb problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
almacmillan  
View profile  
 More options Jul 14 2010, 1:18 pm
From: almacmillan <a.w.macmil...@gmail.com>
Date: Wed, 14 Jul 2010 10:18:24 -0700 (PDT)
Local: Wed, Jul 14 2010 1:18 pm
Subject: Embarrassing Newb problem
Hi there,

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?

Kind thanks
AL


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anand Chitipothu  
View profile  
 More options Jul 14 2010, 1:25 pm
From: Anand Chitipothu <anandol...@gmail.com>
Date: Wed, 14 Jul 2010 22:55:47 +0530
Local: Wed, Jul 14 2010 1:25 pm
Subject: Re: [webpy] Embarrassing Newb problem
2010/7/14 almacmillan <a.w.macmil...@gmail.com>:

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.

Anand


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
almacmillan  
View profile  
 More options Jul 14 2010, 1:32 pm
From: almacmillan <a.w.macmil...@gmail.com>
Date: Wed, 14 Jul 2010 10:32:13 -0700 (PDT)
Local: Wed, Jul 14 2010 1:32 pm
Subject: Re: Embarrassing Newb problem
Hi Anand

I have tested and I have sqlite3 but not pysqlite2

Kind thanks
AL

On Jul 14, 6:25 pm, Anand Chitipothu <anandol...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anand Chitipothu  
View profile  
 More options Jul 14 2010, 1:35 pm
From: Anand Chitipothu <anandol...@gmail.com>
Date: Wed, 14 Jul 2010 23:05:14 +0530
Local: Wed, Jul 14 2010 1:35 pm
Subject: Re: [webpy] Re: Embarrassing Newb problem
2010/7/14 almacmillan <a.w.macmil...@gmail.com>:

> Hi Anand

> I have tested and I have sqlite3 but not pysqlite2

That should be alright then. Can you tell me how you are using datestr function?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
almacmillan  
View profile  
 More options Jul 14 2010, 2:01 pm
From: almacmillan <a.w.macmil...@gmail.com>
Date: Wed, 14 Jul 2010 11:01:58 -0700 (PDT)
Local: Wed, Jul 14 2010 2:01 pm
Subject: Re: Embarrassing Newb problem
Hi Anand

I'm just trying to get the blog example working: http://webpy.org/src/blog/0.3

Kind thanks
AL

On Jul 14, 6:35 pm, Anand Chitipothu <anandol...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
almacmillan  
View profile  
 More options Jul 14 2010, 3:07 pm
From: almacmillan <a.w.macmil...@gmail.com>
Date: Wed, 14 Jul 2010 12:07:28 -0700 (PDT)
Local: Wed, Jul 14 2010 3:07 pm
Subject: Re: Embarrassing Newb problem
I meant to add. I'm trying to use Sqlite3 because I can't get MySQL
configured properly on my mac

On Jul 14, 7:01 pm, almacmillan <a.w.macmil...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
m g  
View profile  
 More options Jul 14 2010, 4:04 pm
From: m g <miles.gro...@gmail.com>
Date: Wed, 14 Jul 2010 16:04:37 -0400
Local: Wed, Jul 14 2010 4:04 pm
Subject: Re: [webpy] Re: Embarrassing Newb problem
I suggest sticking with sqlite3 for development/testing purposes.
Easy to set up.  Easy to tear down.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
almacmillan  
View profile  
 More options Jul 14 2010, 5:13 pm
From: almacmillan <a.w.macmil...@gmail.com>
Date: Wed, 14 Jul 2010 14:13:23 -0700 (PDT)
Local: Wed, Jul 14 2010 5:13 pm
Subject: Re: Embarrassing Newb problem
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oscar Vill  
View profile  
 More options Sep 27 2012, 3:58 pm
From: Oscar Vill <driv...@gmail.com>
Date: Thu, 27 Sep 2012 12:58:50 -0700 (PDT)
Local: Thurs, Sep 27 2012 3:58 pm
Subject: Re: Embarrassing Newb problem

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!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »