【问题标题】:How to insert anti forgery token with Clojure Enlive如何使用 Clojure Enlive 插入防伪令牌
【发布时间】:2014-10-21 16:16:10
【问题描述】:

我尝试使用 ring.util.anti-forgery 将防伪令牌插入 html 表单:

(html/defsnippet post-edit-form "templates/blog.html" [:.post-edit]
   []
   [:form] (html/after (html/html-content (anti-forgery-field))))

获取异常:

java.lang.IllegalArgumentException
Don't know how to create ISeq from: net.cgrand.enlive_html$html_content$fn__5571
RT.java:505 clojure.lang.RT.seqFrom
RT.java:486 clojure.lang.RT.seq
core.clj:133    clojure.core/seq
enlive_html.clj:227 net.cgrand.enlive-html/flatten-nodes-coll[fn]
enlive_html.clj:232 net.cgrand.enlive-html/flatten-nodes-coll[fn]
LazySeq.java:40 clojure.lang.LazySeq.sval
...

也试过这个:

(html/defsnippet post-edit-form "templates/blog.html" [:.post-edit]
  []
  [:form] (html/after (html/html [:input {:id "__anti-forgery-token"
                                          :name "__anti-forgery-token"
                                          :type "hidden"
                                          :value *anti-forgery-token*}])))

不工作:(

(anti-forgery-field) 只生成带有一个“输入”的 html 字符串。但我无法将其插入表单。

【问题讨论】:

    标签: clojure antiforgerytoken enlive


    【解决方案1】:

    完成了!

    需要用html-sn-p代替html-content:

    (html/defsnippet post-edit-form "templates/blog.html" [:.post-edit]
      []
      [:form] (html/append (html/html-snippet (anti-forgery-field))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 2017-10-29
      • 2019-03-05
      • 2018-01-16
      • 2013-11-27
      • 2015-05-11
      相关资源
      最近更新 更多