我正在使用 Clojure/ring/compojure 制作一个网络应用程序,但在路由方面遇到了问题。我有两个文件:web.clj 和landing.clj。我想将导航到 uri 的用户从 web.clj 处理程序路由到 landing.clj 处理程序,并调用 home 函数,该函数将呈现我的应用程序的首页。我似乎无法理解其中的语义,请帮忙。我阅读的文档假设有大量的网络开发知识,而我是初学者。现在,当我从 Leiningen 运行本地服务器时,我在浏览器中收到 404 错误消息。我知道它正在通过 landing.clj 文件中的 defroutes,因为当我加载 http://时,地址栏显示
。http://0.0.0.0:5000/landing
0.0.0.0:5000
这是我的 web.clj 文件的代码,它成功重定向到landing.clj 文件:
(defroutes app
(ANY "/repl" {:as req}
(drawbridge req))
(GET "/" [] (redirect "landing")) ;; come fix this later
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
这是来自landing.clj文件,错误位于GET“/”
函数的某个地方:
(defroutes app
(GET "/" []
{:status 200
:headers {"Content-Type" "text/html"}
:body (home)})
(POST "/" [weights grades] ((process-grades (read-string weights) (read-string grades)) ))
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
最佳答案
下面的表达式似乎有额外的括号:
(POST "/"[权重等级] ((处理等级 (读取字符串权重) (读取字符串等级)) ))
应该是:
(POST "/"[权重等级] (处理等级 (读取字符串权重) (读取字符串等级)) )
关于redirect - Compojure/Clojure 路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983359/