[Twisted-Python] Linking between twisted.web resources.
![](https://secure.gravatar.com/avatar/daf660d6890426570e2e2188f4f7b27e.jpg?s=120&d=mm&r=g)
I've come to the conclusion that linking in twisted.web is way too complicated. Here's an idea: how about keeping track of certain resource's paths so resources under it can link back to it? I just typed the following code as I wrote the email, so there are probably minor bugs, but you should get the idea. class MySite(Interface): def __init__(self): Interface.__init__(self) self.putChild("FooBar", FooBar()) registerPath() #imaginary function def render(self, request): return self.webpage(request, 'MySite', ''' Hi there! welcome to my neato site!<br> <a href="FooBar">Go here!</a> ''' ) class FooBar(Interface): def __init__(self): Interface.__init__(self) def render(self, request) return self.webpage(request, 'FooBar', ''' Hi! This is FooBar. Would you like to go back to my <a href="%s">Main Site?</a> ''' % LinkMe('MySite') ) So, we have registerPath() and LinkMe(). I'm sure it won't be as simple as this, but I do think it should be possible. The main problem we have is handling multiple instances of MySite. During instantiation of MySite, when registerPath() is called, some external data source will be updated with MySite, the path that it's instantiated to, and some sort of ID. Then, somehow, when we want to link to this, we use the LinkMe function. The paramaters will probably need to be the ID and the name of the resource. With this LinkMe design, Resources of completely unrelated sections of the site (ie, resources not under MySite) will be able to link to it without even knowing the path. I know there are many many holes in this idea (for instance, how will resources that want to LinkMe get the ID of the resources to be linked to?), but I really think something like this is needed. Any thoughts? -- Chris Armstrong http://twistedmatrix.com/~carmstro carmstro@dynup.net There is a 90% chance that this message was written when the author's been awake longer than he should have. Please disregard any senseless drivel.
participants (1)
-
Chris Armstrong