【问题标题】:Why can’t compojure-app and hiccup import function hiccup.form/form-to?为什么 compojure-app 和 hiccup 不能导入函数 hiccup.form/form-to?
【发布时间】:2019-06-18 20:58:28
【问题描述】:

我使用“lein new compojure-app”创建一个web项目,在project.clj中已经导入了hiccup:

:dependencies [[org.clojure/clojure "1.8.0"]
             [compojure "1.5.2"]
             [hiccup "1.0.5"]

我可以看到jar文件

我在 home.clj 中使用 intellij 作为 ide:

(ns ansible.routes.home
(:require [compojure.core :refer :all]
        [ansible.views.layout :as layout]
        [hiccup.form :refer :all]
        ))

但是写的时候:

(form-to [ :post "/"]

intellij 告诉我form-to can't be resolved,如果我使用这个:

[hiccup.form :as hf]

然后写

(hf/

intellij 告诉我我可以使用函数:group、input-filed、make-id、make-name、with-group,但没有 form-to,但是 form-to 是包 hiccup.form 中的一个函数

我该如何解决这个问题?

【问题讨论】:

  • org.clojure/clojure "1.8.0"compojure "1.5.2" 是相当旧的版本。尝试使用最新的。
  • 谢谢。我不知道为什么“lein new compojure-app”默认会给我clojure 1.8和compojure 1.5,我使用clojure 1.10和compojure 1.6.1但是错误是一样的

标签: intellij-idea clojure compojure hiccup


【解决方案1】:

通常,将:require:refer :all 一起使用被认为是错误的形式,因为它可能会在您不注意的情况下影响某些功能。

检查您在home.clj 中需要的任何其他命名空间是否已经有一个名为form-to 的函数。尝试使用类似的东西:

(ns myapp.routes.home
  (:require [compojure.core :as cc :refer [defroutes GET]]
            [myapp.views.layout :as layout]
            [hiccup.form :as hf]))

(defn home []
  (layout/common [:h1 "Hello World!"]))

(defroutes home-routes
  (GET "/" [] (home)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2011-02-23
    • 2022-01-15
    相关资源
    最近更新 更多