我想訪問我的Selmer模板中的當前頁面URL,以便我可以將它傳遞給編輯頁面操作,以便即使在編輯之後,此頁面也可以包含返回「調用」頁面的鏈接。簡單的方法來訪問每個selmer模板中的請求映射?
下面是我的塞爾默模板模板代碼 - 這似乎OK:
<a href="/photos/_edit/{{p.path}}{% if back %}?back={{back}}{% endif %}"
class="btn btn-warning btn-sm">edit</a>
下面是如何設置的後值搜索時:
(defn photo-search [word req] (layout/render "search.html" {:word word :photos (db/photos-with-keyword-starting word) :back (str (:uri req) "?" (:query-string req)) })) ;; ... (defroutes home-routes ;; ... (GET "/photos/_search" [word :as req] (photo-search word req))
該工程確定。不過,我有其他方法返回照片列表,它似乎違反DRY原則將此代碼添加到所有其他方法。
有沒有更簡單的方法來做到這一點,也許有一些中間件?