[Twisted-web] Nevow + adbapi
Matt Goodall
matt at pollenation.net
Thu Mar 10 17:08:50 MST 2005
On Thu, 2005-03-10 at 17:34 -0600, Luis N wrote:
> I must be a total moron:
>
> I have this:
>
> def query():
> return dbpool.runQuery("SELECT english FROM lang WHERE spanish LIKE 'hola'")
>
> def result(res):
> if res:
> print res[0][0]
> else:
> print "Failed."
>
> def words(ctx, data):
> query().addCallback(result)
>
> class PData(rend.Page):
> addSlash=True
> docFactory = loaders.stan(tags.html[
> tags.div(data="words")[ words ]])
>
> And I get this at the terminal, which is correct:
>
> 2005/03/10 23:30 GMT [HTTPChannel,0,148.241.73.37] 148.241.73.37 - -
> [10/Mar/2005:23:30:09 +0000] "GET / HTTP/1.1" 200 126 "-" "Mozilla/4.0
> (compatible; MSIE 6.0; Windows NT 5.0)"
> 2005/03/10 23:30 GMT [-] hello
>
> But I get a big red None on the web.
You are not returning the word from the callback chain. The value
returned from a callback chain is the result of the last callback in the
chain. result() needs to return the word if found:
def result(res):
if res:
print res[0][0]
return res[0][0]
else:
print "Failed."
Also, unless you return the deferred from words(), Nevow will not know
it should wait for the deferred to fire:
def words(ctx, data):
return query().addCallback(result)
- Matt
--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: matt at pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
More information about the Twisted-web
mailing list