如何在Mojolicious控制器中更改默认路径

时间:2019-04-08 17:53:07

标签: gnuplot mojolicious

在我的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提出图片的网址。就我而言,我想从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”?

1 个答案:

答案 0 :(得分:0)

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