URL 路由和 GAE
我对 MVC 风格的编程有点陌生,正在研究 一个让我上手的 Python/GAE/jinja2/webapp2 入门应用程序。
我最初在 Werkzeug 级别工作有什么理由吗? 或者,如果 webapp2 不允许我做我需要做的事情,那么这是需要解决的问题吗?
我正在尝试了解路由方面,似乎可以 可以采取多种方式处理。 webapp2 是一个开始的好地方吗? 然后如果需要变得更复杂,如果需要更多,下一个级别是什么 复杂的 URL 路由?
我在 webapp2 网站文档上看到了这一点:
app = webapp2.WSGIApplication([
(r'/', HomeHandler),
(r'/products', ProductListHandler),
(r'/products/(\d+)', ProductHandler),
])
它在它们的外观上是否不是连续的,在这种情况下它会 是列表中最详细的行吗?
但是 app.yaml 文件是连续的,对吧? 但仅限于分组内 - 处理程序、库等......?
I'm a bit new to the MVC style of programming, and am working on
a Python/GAE/jinja2/webapp2 starter app to get my feet wet.
Is there any reason for me to be working at the Werkzeug level initially?
Or is that something to get into if webapp2 doesn't let me do something that I need to do?
I'm trying to understand the routing aspect, and it seems like that can
be handled in various ways possibly. Is webapp2 a good place to start intitially with that,
and then if it needs to get more complex, what would be the next level if needed for more
complex URL routing?
I saw this on the webapp2 site docs:
app = webapp2.WSGIApplication([
(r'/', HomeHandler),
(r'/products', ProductListHandler),
(r'/products/(\d+)', ProductHandler),
])
Is it not sequential in how it looks through them, in which case it would
be the more detailed line first in the list?
But the app.yaml file is sequential, right?
But only within the groupings - handlers, libraries, etc...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实可以在任何您觉得舒服的级别上工作(主要取决于您的要求)。路由的实现方式很大程度上取决于您使用的库/工具。
Pyramid 和 bobo 是您列出的少数几个的替代品,并且以完全不同的方式实现路由。
app.yaml 按顺序处理,就路由而言,处理程序才是最重要的。
我个人对路由的偏好是不使用正则表达式的任何内容;-)
(请参阅金字塔和 bobo)
我倾向于在 app.yaml 中列出尽可能少的处理程序,并将其余的路由行为移至特定的处理程序中。
Rgds
蒂姆
You can really work at whatever level you are comfortable (mostly dictated by your requirements). How routing is implemented is very dependent on what lib/tools you use.
Pyramid and bobo are altenatives to the few you have listed, and implement routing completely differently.
app.yaml is processed in order, and as far as routing is concerned handlers are all that matter.
My personal preference for routing is anything that doesn't use regex's ;-)
(See pyramid and bobo)
I tend to have as few handlers listed as I can in app.yaml, and move the rest of the routing behaviour into the sprecific handler.
Rgds
Tim