1

外部テンプレート ファイルを使用せずに Play 2 からインライン HTML をレンダリングするにはどうすればよいですか?

def checkStatus = Action {
  val status = ...
  if (status.ok) {
    Ok("Status OK")
  } else {
    // Oops, this renders the literal text instead of the HTML I wanted:

    Ok("Bad status, check out <a href='http://help.us.com/'>our help page</a>")
  }
}
4

2 に答える 2

4

Ok("Hello World!")明示的に指定されていない限り、Content-Typeヘッダーを次のように設定します。text/plain

Ok("Bad status, check out <a href='http://help.us.com/'>our help page</a>").as(HTML)

ドキュメント

于 2013-04-28T12:34:14.167 に答える
2

ビューをレンダリングするとき、Play はその型を認識します (少なくとも html、xml、および txtStringの場合text/plain) 。

Manipaliting response docによると、次のタイプで返す必要があります。

 BadRequest("Bad status, check out <a href='http://help.us.com/'>our help page</a>").as("text/html")
于 2013-04-28T12:34:39.553 に答える