[Twisted-web] I can't be the only one who prefers trailing slashes on my URLs...

markscottwright at gmail.com markscottwright at gmail.com
Tue Oct 6 18:38:59 EDT 2009


I've got a resource that a) dynamically builds it's children using getChild  
and b) I'd like to have trailing slashes.

It seems like a lot of work - is there a facility to do this already in  
twisted.web.resource.Resource?

It seems like in every resource's render(), I need to do something like:

def render(self, request):
if request.prepath[-1] != '':
request.redirect(request.childLink(""))
request.finish()
return ""
else:
return resource.Resource.render(self, request)

And every getChild needs to look like this:

def getChild(self, path, request):
if path == '':
return self
elif path == 'edit':
return CrudEdit()
else:
return None

It looks like overriding this wouldn't be much better - since if I still  
want to use render(), the child needs to remember to call  
TrailingSlashResource.render(self, request) in its render() - same with  
getChild. Decorators need to decorate both methods as well.

Is there a facility in twisted.web that does this? I'm not using nevow,  
which appears to just have an addSlash property on it's Page objects.

Thanks all.

markscottwright at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20091006/b292952e/attachment.htm 


More information about the Twisted-web mailing list