Sae*_*fam 1 assets routes playframework playframework-2.0
我的申请中有这条路线:
GET /assets/*file controllers.Assets.at(path="/public", file)
Run Code Online (Sandbox Code Playgroud)
我在scala模板中使用了反向路由,它运行正常:
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.css")">
Run Code Online (Sandbox Code Playgroud)
但是当我为图像添加这条路线时:
GET /images/*file controllers.Assets.at(path="/public/images", file)
Run Code Online (Sandbox Code Playgroud)
我在scala模板中遇到以下错误:
not enough arguments for method at: (path: String, file: String)play.api.mvc.Call.
Unspecified value parameter file.
Run Code Online (Sandbox Code Playgroud)
我不能在Play Framework 2中使用controllers.Assets.at两次或其他什么?
如文档中所述,我相信您可以为您的资产添加一条或多条路线.
这是我认为你错过的重要部分:
此操作将查找文件并提供服务(如果存在).
请注意,如果您在"public"之外定义资产映射,则需要告诉sbt,例如,如果您需要:
GET /assets/*file Assets.at("public", file)
GET /liabilities/*file Assets.at("foo", file)
Run Code Online (Sandbox Code Playgroud)
你应该将它添加到Build.scala:
playAssetsDirectories <+= baseDirectory / "foo"
Run Code Online (Sandbox Code Playgroud)
这用于使用反向路由:
但是,如果为Assets.at操作定义两个映射,如下所示:
GET /javascripts/*file Assets.at("public/javascripts", file)
GET /images/*file Assets.at("public/images", file)
Run Code Online (Sandbox Code Playgroud)
然后,在使用反向路由器时,您需要指定两个参数:
<script src="@routes.Assets.at("public/javascripts", "jquery.js")"></script>
<image src="@routes.Assets.at("public/images", "logo.png")">
Run Code Online (Sandbox Code Playgroud)
编辑:
尝试将您的CSS链接更改为:
<link rel="stylesheet" media="screen" href="@routes.Assets.at("/public","stylesheets/bootstrap.css")">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2892 次 |
| 最近记录: |