clojure - 为什么环在这个响应中给我错误?

标签 clojure ring

下面是我的应用程序 -

(ns mfaiz.routes
  (:use [net.cgrand.moustache :only [app]]
        [net.cgrand.enlive-html :only [deftemplate content]]
        [ring.util.response :only [response]]))

(deftemplate reg "mfaiz/templates/reg.html" [])

(def my-app (app
             ["hi"] "Hello World!"
             ["reg"] (-> ((-> "reg" symbol resolve)) response constantly) 
             [&] "Nothing was found"))

我在这条路线上遇到错误 -

["reg"] (-> ((-> "reg" symbol resolve)) response constantly) 

如果我直接评估上述路由,它会正常工作并返回 html 文件 -

((-> "reg" symbol resolve)) 

如果我也更改路由以直接调用模板函数,那么它也可以工作 -

["reg"] (-> (reg) response constantly)

知道出了什么问题吗?

最佳答案

问题似乎在于,当它在环下运行时,“reg”未得到解析,因为它不完全合格。这取决于环服务器在哪个命名空间中启动。因此,使用完全限定名称即可:

(->“mfaiz.routes/reg”符号解析)

请检查解决 documentation 。它尝试解析当前命名空间中的符号,即 *ns*

关于clojure - 为什么环在这个响应中给我错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12313549/

相关文章:

clojure - Clojure 中的头部保留

clojure - 如何在环项目中运行任意启动功能?

clojure - lein ring uberjar -- java.lang.NoClassDefFoundError : clojure/lang/Var

web-applications - 使用来自 uberjar 的文件响应

clojure - Clojure 中关闭记录背后的基本原理是什么?

clojure - 为什么我不能在线程宏中使用匿名函数?

java - 在 REPL 中使用队列文字时出现 RuntimeException

clojure - 为什么reduce函数会以相反的顺序产生结果?

json - Clojure 使用 ring-json 编码 Joda DateTime

clojure - 在配置文件中正确使用 Environ 库