Racket:将字符串变量插入xexpression属性

时间:2017-04-18 21:21:07

标签: image racket

我正在尝试使用response / xexpr

显示IMG标记

这有效:

SWRevealViewController

这不是:

(define (start req)
  (response/xexpr
   '(html (head (title "Racket Heroku App"))
          (body 
            (h1 "Hello World!")
            (div "it works!!!!")
            (img ([src "https://docs.racket-lang.org/pict/pict_196.png"]))))))

显示的错误如下:

(define example-url "https://docs.racket-lang.org/pict/pict_196.png")

(define (start req)
  (response/xexpr
   '(html (head (title "Racket Heroku App"))
          (body 
            (h1 "Hello World!")
            (div "it works!!!!")
            (img ([src example-url]))))))

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您没有评估example-url变量的值,而是将example-url作为URL传递。试试这个:

(define example-url "https://docs.racket-lang.org/pict/pict_196.png")

(define (start req)
  (response/xexpr
   `(html (head (title "Racket Heroku App"))
          (body 
            (h1 "Hello World!")
            (div "it works!!!!")
            (img ([src ,example-url]))))))

在上面,我使用quasiquoting来评估变量。