尝试找出像 stackoverflow 这样的 sluggale URL 的 URL 调度程序

发布于 2024-09-03 01:18:57 字数 696 浏览 12 评论 0 原文

我正在使用 Tornado 框架 (Python)。我可以使用 sluggable URL。但我在 URL 调度程序中有 3 个不同的条目。我想知道是否有人可以帮我将其转换为一行。

这就是我所拥有的:

(r"/post/([0-9]+)/[a-zA-Z0-9\-]+", SpotHandler),
(r"/post/([0-9]+)/", SpotHandler),
(r"/post/([0-9]+)", SpotHandler),

我想要它,以便以下 URL 都转到同一个地方。

http://domain.com/post/14

http://domain.com/post/14/

http://domain.com/post/14/any-text-it-doesnt-matter-what-it-is

I'm using the Tornado framework (Python). I have the sluggable URLs working. But I have 3 different entries in the URL dispatcher. I was wondering if someone could help me transform it into one line.

This is what I have:

(r"/post/([0-9]+)/[a-zA-Z0-9\-]+", SpotHandler),
(r"/post/([0-9]+)/", SpotHandler),
(r"/post/([0-9]+)", SpotHandler),

I want it so that the following URLs all go to the same place.

http://domain.com/post/14

http://domain.com/post/14/

http://domain.com/post/14/any-text-it-doesnt-matter-what-it-is

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

乖乖哒 2024-09-10 01:18:57
r"/post/([0-9]+)(?:/[a-zA-Z_-]+|/)?"
r"/post/([0-9]+)(?:/[a-zA-Z_-]+|/)?"
念﹏祤嫣 2024-09-10 01:18:57

(r"/post/([0-9]+)/?[a-zA-Z_]*", SpotHandler),

"?"意味着先前的事物可以存在但不一定存在。
“*”表示零个或多个

(r"/post/([0-9]+)/?[a-zA-Z_]*", SpotHandler),

"?" means previous thing can be there but need not be.
"*" means zero or more

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