Hi,

I am currently trying to use Twisted to develop my Web-based application. And I 
am trying to use twisted.enterprise.adbapi to handle my database connection and 
etc.  I tried the example provide by the online docs.
It work ONLY with print, without return a value for my Mako template. Can 
someone give a small example that lighten me how to use it? 

Here is some of my code.

-----database.py-----------

from twisted.enterprise import adbapi
from twisted.internet import defer

class DBModule():

    connection_pool = adbapi.ConnectionPool("psycopg2", host = "localhost", 
database = "2juban" ,user = "2juban", password = "2juban" ) 
    
    table = " "
    
    def findById(self, field, id):
            
        if field =="all":
            field = "*"          
        
        query = """SELECT """+field+""" from """+ self.table +""" where id=""" 
+ str(id)
        row = self.connection_pool.runQuery(query)
        return row.addCallback(self.print_data)
    
    def print_data(self, data):
                      
        print data
        #return data

----hello.rpy-------

...
from tpp.module.database import DBModule

class hello(Controller):

    d = DBModule()
    d.table = 'talk_talk'
    
    
    t1 = d.findById('content',2)

...
..
.


The problem is when I just print out the value , it works ! I can saw it in my 
eclipse console. But if I want to get the return of the value, it's nothing 
rather a Deferred<>.

Thanks.

_________________________________________________________________
Connect to the next generation of MSN Messenger 
http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to