redirect - Compojure/Clojure 路由错误

标签 redirect clojure routes compojure ring

我正在使用 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/

相关文章:

asp.net-mvc-3 - 带有区域的 MVC -- Html.ActionLink 返回错误的 URL/路由?

.htaccess - ssl 重定向不工作

javascript - 有什么方法可以在不触摸窗口或文档的情况下重定向?

clojure - the -> 宏和偏函数

java - 使 Java 类在 Clojure 中作为序列工作

heroku - 全新的 Luminus 应用程序给出错误 : Could not find or load main class clojure. main

ruby-on-rails - Rails 3.1 - 如何为同一模型组织多个索引操作?

php - 在路由中使用连字符 (-) 而不是斜杠 (/) 或下划线 (_)

java - 使用重定向的 Jsoup 登录网站,并抓取非重定向的页面

.htaccess - 创建 Google 友好文件夹