我正在嘗試製作一個web應用,幫助教師在線計算他們的成績。我使用lein new heroku命令創建它,並且無法讓我的路由器排序並顯示首頁。任何幫助,將不勝感激!這裏是我的defroutes的樣子。它是在同一個文件夾中的文件web.clj的頁面我想已經呈現:Clojure Heroku網頁應用:頁面不會在瀏覽器中呈現
(ns clojuregrade.web
(:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
[compojure.handler :refer [site]]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.middleware.stacktrace :as trace]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
[ring.adapter.jetty :as jetty]
[ring.middleware.basic-authentication :as basic]
[cemerick.drawbridge :as drawbridge]
[environ.core :refer [env]]))
(defroutes app
(ANY "/repl" {:as req}
(drawbridge req))
(GET "/" []
{:status 200 ;; <- this is where it says the error is showing up
:headers {"Content-Type" "text/plain"}
:body (pr-str (slurp (io "landing.clj"))) ;; <- I am guessing here
(ANY "*" []
(route/not-found (slurp (io/resource "404.html"))))
這與頁面的代碼,我想已經呈現:
(ns clojuregrade.landing
(:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
[compojure.handler :refer [site]]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.middleware.stacktrace :as trace]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
[ring.adapter.jetty :as jetty]
[hiccup.core :refer :all]
))
...
(defn home [& [weights grades error]]
(layout/common
[:h1 "Welcome to Clojure-grade"]
[:hr]
(form-to [:post "/"]
[:p "Enter the weights for your various grades below. For example if you have quizzes, homework and tests
and they are worth 40% 10% and 50% respectively, you can enter: [40 10 50].
Of course, all of the numbers should add up to 100%. Be sure to include the brackets"
(text-field {:placeholder "[40 10 50]"} "weights" weights)]
[:p "Enter ALL of the grades for EACH STUDENT in your class.
Make sure that each of the grades is ordered such that the grade corresponds
to its matching weight above. Use brackets to separate students from each other.
Each set of grades should have the same number of grades as the number of possible weights (3 in this example case).
The following example shows grades for 4 students. Format your grades according to the number of students in your class:"
(text-area {:rows 40 :cols 40 :placeholder
"[89 78 63]
[78 91 60]
[54 85 91]
[100 89 77]
..." } "grades" grades)]
(submit-button "process"))))
(defn process-grades [weights grades]
(->> (float grades)
(map (partial percentify-vector (float weights)))
(mapv #(apply + %))))
(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")))))
(defn wrap-error-page [handler]
(fn [req]
(try (handler req)
(catch Exception e
{:status 500
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "500.html"))}))))
非常感謝!我會實施你的建議並做更多的教程。我是全新的品牌:代碼,Clojure和網頁開發。學習曲線非常陡峭。我目前正在使用Clojure的書進行Web開發,並且已經從Github的頂部到底部閱讀了Ring和Compojure概述。我已經做了幾個教程,現在正在嘗試採取寶貝步驟來自己做一些事情。儘管如此,將它們結合在一起仍然是一項挑戰。任何固體(最新)教程建議,真正解釋了我需要的細節,將不勝感激。 – kurofune