我尝试使用 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 字符串。但我无法将其插入表单。