It's actually fairly straight-forward. All we need to do is the following:
- Create a tuple of patterns.
- Override the locateChild() method in our "root" class.
urlPatterns = (Then, in SiteRoot, we could do something like the following:
def locateChild(self, context, segments):What we're doing here is interrupting the "natural" flow of Nevow's path processing. If there are more segments once we've found a match, we pass the additional segments on to the child resource's locateChild() method. If not, we have a final destination and can return the resource itself.
path = '/'.join(('',) + segments)
for regex, resource in urlPatterns:
match = re.match(regex, path)
newPath = match.groups()
r = resource()
if newPath in ['', '/']:
return r, ()
newSegments = newPath.split('/')[1:]
return r.locateChild(context, newSegments)
return super(SiteRoot, self).locateChild(context, segments)
Here are some screenshots of this in action:
You can browse the code for this at the following links: