- 论坛徽章:
- 0
|
TGNewTravesal用的是Nevow同样的REST风格的URL定位,看源代码可得出它的定位过程:
#定位method
(0)如果未处理的URL 段(segments)元素个数是0,则调用index。
(1)在resource里查看是否有expose的method和url段(segments)的第一个元素相同
#定位resource
(2)如果没找到,则认为此段是child resource
(3)在resource 的self.children字典里找
(5)在child_里找,此method 或属性应该的返回对象应该能转换成resource
(6)调用self.childFactory(ctx, name)
(7)如果以上都没找到则raise NotFound
这里要注意一个问题,就是“http://site/child/” 和"http://site/child"都能访问到"http://site/child/index",但是index中的相对连接method在浏览器请求时,前者转换成绝对连接是“http://site/child/method”,而后者是“http://site/method”!!!后者显然不是我们需要的!
另外:按照上面的travesal rule,如果一个method和child resource都叫做somename,则会访问method,而不是child resource。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8650/showart_280102.html |
|