我是 clojure 和 compojure 的新手,并尝试使用 compojure 和 Ring 来创建一个基本的 Web 应用程序。
这是我的 handler.clj
(ns gitrepos.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.util.response :as resp]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]))
(defroutes app-routes
(GET "/" [] (resp/file-response "index.html" {:root "public"}))
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
我有这个索引.html文件下/资源/公共但应用程序没有渲染这个 html 文件。相反得到未找到
我已经搜索了很多,甚至这个Compojure 中默认在 / 处提供 index.html https://stackoverflow.com/questions/7729628/serve-index-html-at-by-default-in-compojure似乎并不能解决问题。
不知道我在这里缺少什么。
也许您想尝试使用一些模板库,例如Selmer https://github.com/yogthos/Selmer。所以你可以这样做:
(defroutes myapp
(GET "/hello/" []
(render-string (read-template "templates/hello.html"))))
或者传递一些值:
(defroutes myapp
(GET "/hello/" [name]
(render-string (read-template "templates/hello.html") {name: "Jhon"})))
而且,正如 @piotrek-Bzdyl 所说:
(GET "/" [] (resource-response "index.html" {:root "public"}))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)