在 Play 中路​​由到静态文件!2.0 [英] Route to static file in Play! 2.0

查看:15
本文介绍了在 Play 中路​​由到静态文件!2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建指向特定静态文件的路由,但我尝试的所有操作都以错误结束.

I'm trying to make a route to a specific static file but everything I'm trying ends with an error.

我进行了 3 次不同的尝试:

I've made 3 different attempts:

1.

GET /file   staticFile:/public/html/file.html

我得到的错误:

Compilation error
string matching regex `z' expected but `:' found

2.

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

我得到的错误:

Compilation error
Identifier expected

3.

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

我得到的错误:(这是最奇怪的)

The error I get: (and this is the weirdest)

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

关于第三个错误的奇怪部分是它在以下行的不同文件(app/views/main.scala.html)中被抛出:

The weird part about the 3rd error is that it's thrown in a different file (app/views/main.scala.html) on the following line:

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

所有这些方法都可以在官方文档和/或 stackoverflow 上的线程中找到.我在这里错过了什么?

All of these methods were found in the official documentation and/or threads here on stackoverflow. What am I missing here?

谢谢.

推荐答案

IIRC,改变

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

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

我说的是你的第三次尝试

I am talking about your third attempt

另外,注意额外/

编辑

GET /assets/main.css    controllers.Assets.at(path="/public", file="/stylesheets/main.css")

假设您的资源位于/public/stylesheets/main.css

Assuming your resource is at /public/stylesheets/main.css

这篇关于在 Play 中路​​由到静态文件!2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆