Opened 4 years ago

Closed 4 years ago

#6237 enhancement closed wontfix (wontfix)

t.w._flatten._flattenElement doesn't support objects adaptable to IRenderable

Reported by: tom.prince Owned by:
Priority: normal Milestone:
Component: web Keywords: web templates
Cc: jknight Branch:


In porting some code from nevow, I tried to adapt nevow.url.URL as a stop-gap with

from twisted.python.components import registerAdapter
from zope.interface import implements
from twisted.web.iweb import IRenderable
class _URLAdapter(object):
    def __init__(self, url):
        self.url = url
    def render(self, req):
        return str(self.url)

registerAdapter(_URLAdapter, URL, IRenderable)

Attachments (2)

t.w.template-adapter-support-6237.patch (4.4 KB) - added by tom.prince 4 years ago.
Patch to add support for adapters
t.w.template-adapter-support-6237-2.patch (4.4 KB) - added by tom.prince 4 years ago.
(fixed patch)

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by DefaultCC Plugin

  • Cc jknight added

comment:2 Changed 4 years ago by exarkun

  • Owner set to tom.prince

This is intentionally, as I recall. You can adapt the object explicitly, instead. Just return _URLAdapter(url) where you planned to return url.

Changed 4 years ago by tom.prince

Patch to add support for adapters

Changed 4 years ago by tom.prince

(fixed patch)

comment:3 Changed 4 years ago by tom.prince

  • Keywords review added

I can't find any discussion of the decision anywhere, and the nevow code from which it derives appears to have support for this.

I've attached code that implements this.

I don't see any obvious place where explicit documentation could be added.

And twisted/web/topfiles/6237.feature

twisted.web.template now supports anything adaptable to IRendrable.

comment:4 Changed 4 years ago by exarkun

Reasons not to support this:

  • It's slow (but I realize we don't have any benchmarks)
  • It's rarely what a non-trivial project wants: you can only register *one* adapter, so you can only have one rendering behavior. Turns out most non-trivial objects (ie, things that aren't integers or strings) can usually be rendered in a number of ways, and using the interface adaption API for this gets in the way.
  • It's easy to achieve the desired behavior without this feature: just construct _URLAdapter(url) yourself.

comment:5 Changed 4 years ago by tom.prince

  • Owner tom.prince deleted

comment:6 Changed 4 years ago by exarkun

  • Keywords review removed
  • Resolution set to wontfix
  • Status changed from new to closed

glyph and dreid agreed with at least points two and three from my comment above. So I think we'll say that flattening will not support objects that are adaptable to IRenderable (but do not provide IRenderable), at least until some counterpoints are made.

Note: See TracTickets for help on using tickets.