【发布时间】:2014-03-25 20:32:19
【问题描述】:
我正在使用 Clojure/ring/compojure 制作一个网络应用程序,但遇到路由问题。我有两个文件:web.clj 和landing.clj。我想将导航到 uri 从 web.clj 处理程序的用户路由到landing.clj 处理程序,并调用 home 函数,该函数将呈现我的应用程序的首页。我一生都无法理解语义,请帮忙。我阅读的文档假设有很多网络开发知识,而且我是初学者。当我从 Leiningen 运行本地服务器时,我现在在浏览器中收到 404 错误消息。我知道它正在通过landing.clj文件中的defroutes,因为地址栏显示http://0.0.0.0:5000/landing,当我加载http://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")))))
【问题讨论】:
标签: redirect clojure routes compojure ring