Opened 4 years ago

Last modified 3 years ago

#4983 enhancement new

Document twisted.web.template usage in Resource.

Reported by: jerub Owned by:
Priority: normal Milestone:
Component: web Keywords: documentation
Cc: jknight Branch:
Author: Launchpad Bug:

Description

twisted.web.template docs only show how to template in a static context, not inside a twisted.web server.

The docs should show a simple usage inside a twisted.web server, perhaps including a (working) snippet along these lines:

    def render(self, request):
        element = SomeElement(...)
        flatten(request, element, request.write).addCallbacks(lambda _:request.finish)
        return server.NOT_DONE_YET

Change History (5)

comment:1 Changed 4 years ago by DefaultCC Plugin

  • Cc jknight added

comment:2 follow-up: Changed 4 years ago by exarkun

Rendering incrementally into the response is a mixed bag. I think people should render into a string and then write the string to the response all at once. If you encounter an error while flattening, it's hard to display the error coherently if a random prefix of your page has already been sent to the browser. You also have to deal with the client disconnecting partway through.

comment:3 Changed 4 years ago by exarkun

  • Keywords documentation added

comment:4 in reply to: ↑ 2 Changed 4 years ago by glyph

Replying to exarkun:

Rendering incrementally into the response is a mixed bag. I think people should render into a string and then write the string to the response all at once. If you encounter an error while flattening, it's hard to display the error coherently if a random prefix of your page has already been sent to the browser. You also have to deal with the client disconnecting partway through.

It would be possible, however, to address these issues with a sufficiently smart resource object that knew stuff about what was being rendered. This is why I didn't include a resource object though: the implementation that was feasible to do as part of the initial feature would have simply gotten error-reporting wrong, and I didn't want to have to provide compatibility and a deprecation for that.

comment:5 Changed 3 years ago by glyph

I just filed #5395 for just implementing the appropriate sufficiently-smart resource. Perhaps these will be resolved together.

Note: See TracTickets for help on using tickets.