web.py url 处理:多个子应用程序重定向
使用 web.py 框架时。您可以将 URL 重定向到子应用程序。 例如(code.py):
import web
import subapp1
urls = (
"/sub1", subapp1.app,
"/(.*)", "index"
)
....
这真的很简单。
但是,当编写有自己的 url 处理程序的 subapp1.py 时,如果我想将某些 url(例如“/sub2”)重新路由到另一个子应用程序(subapp2),我会失败。
以前在 subapp1.py 中
import web
import subapp2
urls = (
"/sub2", subapp2.app,
"/(.*)", "some_local_class"
)
....
,对“/sub1/sub2/”的 GET 请求由supapp1.py 中的“some_local_class”处理。但我需要将此网址重新路由到 subapp2.py。
我有什么遗漏的吗?或者这可能是 web.py 中不推荐的 url 处理方法?
When using web.py framework. you can redirect an url to a subapplication.
e.g (code.py):
import web
import subapp1
urls = (
"/sub1", subapp1.app,
"/(.*)", "index"
)
....
this is really straight forward.
However, when writing subapp1.py which has its own url handlers, if i want to re-route some url, say '/sub2', to another subapplication (subapp2), i am failing.
Formerly in subapp1.py
import web
import subapp2
urls = (
"/sub2", subapp2.app,
"/(.*)", "some_local_class"
)
....
GET request to "/sub1/sub2/", is handled by "some_local_class" in supapp1.py. But i need this url is re-routed to subapp2.py.
Is there anything i am missing? Or may be this is not recommended url handling methodology in web.py?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番尝试,发现 web.py 并从子应用程序重新路由到另一个子应用程序没有任何问题。一切都很完美。
问题出在我的方法上。不要尝试在包的 init.py 文件中创建子应用程序。至少当我将子应用程序移动到它自己的模块时,一切都运行良好。
After some trial-error, found that there is nothing wrong with web.py and rerouting from subapp to another subapp. It is all working perfectly.
What is wrong is my method. Do not try to create a subapp in package's init.py file. At least when i moved subapp to its own module, it all worked well.