Hello,

I want to attach the result of a database SELECT query to the response of
a HTTP GET request.

In twisted.web I've done it this way:

------------------------------
from twisted.web import resource, server, http
from twisted.enterprise import adbapi

class Site(resource.Resource):
    ...
def render(self, request):
       query = "SELECT data FROM test"
       self.db.runQuery(query).addCallback(
           self._gotData, request).addErrback(
           self._dbError, request)
       return server.NOT_DONE_YET

   def _gotData(self, results, request):
       request.write("%s" % data[0])
       request.write(body)
       request.finish()

   def _dbError(self, failure, request):
       request.setResponseCode(http.INTERNAL_SERVER_ERROR)
       request.write("Error fetching data.")
       request.finish()
------------------------------

What is the best way to perform the same operation in web2? A
web2.server.NOT_DONE_YET constant is not defined.

In other words, how could I return a defer-related response
instead of a simple http.Response object ?

Thank you.

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to