Route to static file in Play! 2.0

后端 未结 9 1748
甜味超标
甜味超标 2021-01-30 14:05

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

I\'ve made 3 different attempts:

1.

GET /fil         


        
9条回答
  •  深忆病人
    2021-01-30 14:30

    Your third attempt was almost right. Instead of

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

    do it like this

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

    I got the same issue before. My route file looks like this.

    # Application
    GET /       controllers.Assets.at(path="/public/html", file="static.html")
    GET /exmpl  controllers.Examples.index
    
    # Resources
    GET /assets/*file  controllers.Assets.at(path="/public", file)
    

    And I have below reverse route inside views (examples.scala.html)

    @routes.Assets.at("imagefolder")   #try to generate path to /public/imagefolder.
    

    When I open http://localhost:9000/exmpl, this error showed up.

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

    To fix this issue, I just changed this route

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

    to this

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

    This solution was works for me. I hope it works for you and the others too.

提交回复
热议问题