【问题标题】:How to change default path in Mojolicious controller如何更改 Mojolicious 控制器中的默认路径
【发布时间】:2019-04-16 01:39:23
【问题描述】:

在我的 Mojolicious 应用程序中,我嵌入了一个从 gnuplot 生成的 SVG 文件。问题是 gnuplot 忽略了 grid.png 的 jsdir 并将其保留为相对路径。

  <image x='10' y='274' width='16' height='16' xlink:href='grid.png'
    onclick='gnuplot_svg.toggleGrid();'/>

这会导致 Mojolicious 提供图片的 URL。在我的例子中,我想从 public/ 目录访问这个文件,但是我的控制器想要找到与它的路径相关的它。

[2019-04-08 10:19:21.46569] [28105] [debug] GET "/reports/grid.png" (e9f0c2a8)
[2019-04-08 10:19:21.46596] [28105] [debug] Routing to controller "WebLOC::Controller::Auth" and action "check"
[2019-04-08 10:19:21.46632] [28105] [debug] Routing to controller "WebLOC::Controller::Reports" and action "grid"
[2019-04-08 10:19:21.46637] [28105] [debug] Action not found in controller
[2019-04-08 10:19:21.46658] [28105] [debug] Template "reports/grid.png.ep" not found
[2019-04-08 10:19:21.46679] [28105] [debug] Template "not_found.development.png.ep" not found
[2019-04-08 10:19:21.46696] [28105] [debug] Template "not_found.png.ep" not found
[2019-04-08 10:19:21.46713] [28105] [debug] Template "not_found.development.html.ep" not found
[2019-04-08 10:19:21.46729] [28105] [debug] Template "not_found.html.ep" not found
[2019-04-08 10:19:21.46739] [28105] [debug] Rendering cached template "mojo/debug.html.ep"
[2019-04-08 10:19:21.46851] [28105] [debug] Rendering cached template "mojo/menubar.html.ep"
[2019-04-08 10:19:21.47419] [28105] [debug] 404 Not Found (0.008486s, 117.841/s)

我怎样才能拥有 Mojolicious GET “/grid.png”,而不是“/reports/grid.png”?

【问题讨论】:

  • 有趣。我认为这是一个简单的答案,我只是在大量的 Mojolicious 文档中找不到。那好吧。我通过回到 gnuplot 中的画布(HTML5)终端来“解决”这个问题。在这一点上,这对我来说似乎是一个更好的解决方案。

标签: gnuplot mojolicious


【解决方案1】:

这实际上与 Mojolicious 无关,而是与 XML/HTML 相关。 XML 中的路径“grid.png”将相对于当前 URL 路径进行解释。如果它在您的根目录中,您需要与域相关的路径“/grid.png”。如果您的网站未部署为域根目录,您可能需要使用 url_for 帮助程序。

【讨论】:

  • 感谢您的回复,但这对我的情况没有帮助。问题是,无论对错,gnuplot 正在生成这个 href。我对它没有太多控制权。如果我正在生成 XML,它可以很容易地修复。
猜你喜欢
  • 2021-10-25
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多