erlang n2o render get< span id =“

时间:2016-08-02 06:25:13

标签: web erlang n2o

我想用n2o和rebar3写网页。 但是我的页面出错了,代码在这里。

index.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]} ].

prod.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>

我怎样才能得到'&lt;'不是'&amp; lt'

1 个答案:

答案 0 :(得分:0)

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

而不是:

{{ body }}

做的:

{{ body | safe }}

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