我尝试使用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)只生成带有一个'input'的html字符串。但我无法将其插入表格。
答案 0 :(得分:3)
完成它!
需要使用html-snippet而不是html-content:
(html/defsnippet post-edit-form "templates/blog.html" [:.post-edit]
[]
[:form] (html/append (html/html-snippet (anti-forgery-field))))