Django、Rails 路由...点?

发布于 07-11 04:36 字数 472 浏览 8 评论 0原文

我是一名网络开发(和大学)的学生,所以如果这听起来很天真和冒犯,我很抱歉,我当然不是那个意思。 我的经验是使用 PHP 和即将到来的一个小型项目(一个美化的轮班日历),我希望学习一个更高级别的框架来减轻代码负担。 到目前为止,我研究了 CakePHP、Symfony Django 和 Rails。

使用 PHP,URL 可以非常简单地映射到文件,并且它“正常工作”。 对于服务器来说速度很快,而且很直观。 但对于所有这些框架,都倾向于通过使 URL 映射到不同的函数并将参数路由到不同文件中的不同变量来“美化”URL。

我正在阅读的《The Rails Way》一书承认这太慢了,并且是大型项目中大多数性能问题的原因。 我的问题是“为什么首先要有它?”? url-maps-to-a-file 范例(或 mod_rewrite 到单个文件)中是否有特定的点需要正则表达式和复杂的路由方案? 如果不使用它们,我是否会错过一些东西?

提前致谢!

I'm a student of web development (and college), so my apologies if this comes off sounding naive and offensive, I certainly don't mean it that way. My experience has been with PHP and with a smallish project on the horizon (a glorified shift calendar) I hoped to learn one of the higher level frameworks to ease the code burden. So far, I looked at CakePHP Symfony Django and Rails.

With PHP, the URLs mapped very simply to the files, and it "just worked". It was quick for the server, and intuitive. But with all of these frameworks, there is this inclination to "pretty up" the URLs by making them map to different functions and route the parameters to different variables in different files.

"The Rails Way" book that I'm reading admits that this is dog slow and is the cause of most performance pains on largish projects. My question is "why have it in the first place?"? Is there a specific point in the url-maps-to-a-file paradigm (or mod_rewrite to a single file) that necessitates regexes and complicated routing schemes? Am I missing out on something by not using them?

Thanks in advance!

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

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

发布评论

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

评论(6

極樂鬼2024-07-18 04:36:57
  • URL 应该易于记忆和说出。 用户应该知道当她看到该 URL 时会发生什么。 将 URL 直接映射到文件并不总是允许这样做。
  • 您可能希望对显示的相同或至少相似的信息使用不同的 URL。 如果您的服务器强制您使用 1 个 url <-> 1 文件映射,您需要创建其他文件,其所有功能都是重定向到其他文件。 或者你使用像 mod_rewrite 这样的东西,这并不比 Rails 的 url 映射更容易。
  • 在我的一个应用程序中,我使用类似于 http://www.example.com/用户名/一些其他内容的 URL <代码>/。 这也可以使用mod_rewrite来实现,但至少对我来说,在django项目中配置url比在我运行应用程序的每个apache实例中配置url更容易。

只是我的2分钱...

  • URLs should be easy to remember and say. And the user should know what to expect when she see that URL. Mapping URL directly to file doesn't always allow that.
  • You might want to use diffrent URLs for the same, or at least similar, information displayed. If your server forces you to use 1 url <-> 1 file mapping, you need to create additional files with all their function being to redirect to other file. Or you use stuff like mod_rewrite which isn't easier then Rails' url mappings.
  • In one of my applications I use URL that looks like http://www.example.com/username/some additional stuff/. This can be also made with mod_rewrite, but at least for me it's easier to configure urls in django project then in every apache instance I run application at.

just my 2 cents...

走过海棠暮2024-07-18 04:36:57

大部分内容已经被涵盖,但还没有人提到 SEO。 Google 对 URL 本身给予了很大的重视,如果该 URL 是 widgets.com/browse.php?17,那对 SEO 不太友好。 如果您的 URL 是 widgets.com/products/buttons/ 这将对按钮的页面排名产生积极影响

Most of it has already been covered, but nobody has mentioned SEO yet. Google puts alot of weight on the URL itself, if that url is widgets.com/browse.php?17, that is not very SEO friendly. If your URL is widgets.com/products/buttons/ that will have a positive impact on your page rank for buttons

撩心不撩汉2024-07-18 04:36:57

将应用程序代码存储在 Web 服务器的文档树中是一个安全问题。

  • 配置错误可能会意外地向访问者泄露源代码
  • 通过安全漏洞注入的文件可通过 HTTP 请求立即执行
  • 备份文件(例如由文本编辑器创建)可能会泄露代码或在配置错误的情况下可执行
  • 管理员未能删除的旧文件可以揭示非预期的功能
  • 对库文件的请求必须明确拒绝
  • URL 揭示实现细节(使用了哪种语言/框架)

请注意,只要其他事情不出错(其中一些错误会即使独自一人也要认真)。 但总会出现问题,额外的防线是有好处的。

Storing application code in the document tree of the web server is a security concern.

  • a misconfiguration might accidentally reveal source code to visitors
  • files injected through a security vulnerability are immediately executable by HTTP requests
  • backup files (created e.g. by text editors) may reveal code or be executable in case of misconfiguration
  • old files which the administrator has failed to delete can reveal unintended functionality
  • requests to library files must be explicitly denied
  • URLs reveal implementation details (which language/framework was used)

Note that all of the above are not a problem as long as other things don't go wrong (and some of these mistakes would be serious even alone). But something always goes wrong, and extra lines of defense are good to have.

最美的太阳2024-07-18 04:36:57

Django URL 也是非常可定制的。 使用像 Code Igniter(我不确定 Rails)这样的 PHP 框架,你被迫进入 /class/method/extra/ URL 结构。 虽然这可能适合小型项目和应用程序,但一旦您尝试使其更大/更动态,您就会遇到问题,并且必须重写一些框架代码来处理它。

Django URLs are also very customizable. With PHP frameworks like Code Igniter (I'm not sure about Rails) your forced into the /class/method/extra/ URL structure. While this may be good for small projects and apps, as soon as you try and make it larger/more dynamic you run into problems and have to rewrite some of the framework code to handle it.

醉态萌生2024-07-18 04:36:57

此外,路由器类似于 mod_rewrite,但更加灵活。 它们不受正则表达式限制,因此对于不同类型的路由有更多选择。

Also, routers are like mod_rewrite, but much more flexible. They are not regular expression-bound, and thus, have more options for different types of routes.

暖树树初阳…2024-07-18 04:36:57

取决于您的应用程序有多大。 我们有一个相当大的应用程序(50 多个模型),它不会给我们带来任何问题。 当它发生时,我们就会担心它。

Depends on how big your application is. We've got a fairly large app (50+ models) and it isn't causing us any problems. When it does, we'll worry about it then.

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