gpt4 book ai didi

playframework - 在 Play Framework 2 中使用多个 Assets 路由

转载 作者:行者123 更新时间:2023-12-05 01:30:35 25 4
gpt4 key购买 nike

我的申请中有这条路线:

GET    /assets/*file   controllers.Assets.at(path="/public", file)

我在 Scala 模板中使用了反向路由,它工作正常:

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.css")"> 

但是当我为图像添加这条路线时:

GET   /images/*file   controllers.Assets.at(path="/public/images", file)

我在正常工作的 Scala 模板中遇到以下错误:

not enough arguments for method at: (path: String, file: String)play.api.mvc.Call.
Unspecified value parameter file.

我不能在 Play Framework 2 或其他东西的路由中使用 controllers.Assets.at 两次?

最佳答案

documentation 中所述,我相信您可以为您的 Assets 添加 1 条或多条路线。

这是我认为您错过的重要部分:

This action will look-up the file and serve it, if it exists.

Note, if you define asset mappings outside “public,” you’ll need to tell sbt about it, e.g. if you want:

GET  /assets/*file               Assets.at("public", file)
GET /liabilities/*file Assets.at("foo", file)

you should add this to Build.scala:

playAssetsDirectories <+= baseDirectory / "foo"

这是为了使用反向路由:

However, if you define two mappings for the Assets.at action, like this:

GET  /javascripts/*file        Assets.at("public/javascripts", file)
GET /images/*file Assets.at("public/images", file)

Then you will need to specify both parameters when using the reverse router:

<script src="@routes.Assets.at("public/javascripts", "jquery.js")"></script>
<image src="@routes.Assets.at("public/images", "logo.png")">

编辑:

尝试将您的 CSS 链接更改为:

<link rel="stylesheet" media="screen" href="@routes.Assets.at("/public","stylesheets/bootstrap.css")"> 

关于playframework - 在 Play Framework 2 中使用多个 Assets 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25217624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com