2014-10-20 71 views
1

我嘗試使用ring.util.anti僞造成HTML表單插反僞造令牌:如何插入防僞造令牌使用Clojure Enlive

(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*}]))) 

不工作:(

(防僞字段)只用一個「輸入」產生html字符串。但我不能將它插入到表單中。

回答

3

完成它!

需要使用HTML的代碼片段,而不是HTML的內容:

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