A render_GET method cannot return Deferred . It can only return a string or NOT_DONE_YET . Any method decorated with inlineCallbacks will return a Deferred . Thus, you cannot decorate render_GET with inlineCallbacks .
Of course, nothing prevents you from calling any other function that you want in render_GET , including the one that returns Deferred . Just drop Deferred and not return it from render_GET (of course, make sure that Deferred never fails or throws it, maybe you are missing error messages ...).
So for example:
@inlineCallbacks def _renderContacts(self, request): contacts = yield Contact.find() for c in contacts: request.write(c.name) if not request.finished: request.finish() def render_GET(self, request): self._renderContacts(request) return NOT_DONE_YET
I recommend that you at least take a look at txyoga and klein if you intend to do serious web development with Twisted. Even if you don't want to use them, they should give you some good ideas on how you can structure your code and perform various common tasks, such as this one.
Jean-paul calderone
source share