1

我想用 n2o 和 rebar3 写网页。但我的页面有问题,代码在这里。

索引.erl

-module(index).
  -compile(export_all).
  -include_lib("n2o/include/wf.hrl").
  -include_lib("nitro/include/nitro.hrl").




  main() -> #dtl{file="prod",app=web, ext="dtl", bindings=[{body,body()} ]}.

  body() ->
      [ #span   { id=display },                #br{},
        #span   { body="Login: " },            #textbox{id=user,autofocus=true}, #br{},
        #span   { body="Join/Create Feed: " }, #textbox{id=pass},
        #button { id=loginButton, body="Login",postback=login,source=[user,pass]} ].

产品.dtl

<html >
<head>
  <title>{{title}}</title>
</head>
<body>
            {{body}}
</body>
</html>

我得到结果:

<html >
<head>
  <title></title>
</head>
<body>
            &lt;span id=&quot;display&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;span&gt;Login: &lt;/span&gt;&lt;input id=&quot;user&quot; type=&quot;text&quot; autofocus=&quot;true&quot;/&gt;&lt;br/&gt;&lt;span&gt;Join/Create Feed: &lt;/span&gt;&lt;input id=&quot;pass&quot; type=&quot;text&quot;/&gt;&lt;button id=&quot;loginButton&quot; type=&quot;button&quot;&gt;Login&lt;/button&gt;
</body>
</html>

我怎样才能得到'<'而不是'<'

4

1 回答 1

0

erlydtl{{}}启用了此提交中值的自动转义(另请参见#80#120)。如果您正在使用包含此提交的版本(从页面上看,它看起来像 0.9.0 或更高版本),您必须手动将该值标记为安全。

代替:

{{ body }}

做:

{{ body | safe }}

注意:您应该意识到将不受信任的字符串标记为安全的风险:https ://en.wikipedia.org/wiki/Cross-site_scripting 。

于 2016-08-02T09:02:26.903 回答