web.py url 处理:多个子应用程序重定向

发布于 2024-10-25 01:36:59 字数 569 浏览 1 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撧情箌佬 2024-11-01 01:36:59

经过一番尝试,发现 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文