dtcd27183 2014-11-19 03:08
浏览 99

图像未显示在Golang上带有img的html上的文字

image didnt show when writing on html.

        i can display only image writing on main.go (parsefile).

       but writing on html image didnt show.

i tried html/template. it didnt work too.

code: _base.html

   <!DOCTYPE html>
    <html lang="en">`enter code here`
        <head>
            <title>{{ template "title" . }}</title>
        </head>
        <body>
            <section id="contents">
                {{ template "content" . }}
            </section>
            <footer id="footer">
                My Cool Guestbook 2000 © me forever
            </footer>
        </body>
    </html>

    code:(index.html)

    {{ define "title" }}Guestbook{{ end }}

    {{ define "content" }}
        <h1>Guestbook</h1>

        <p>Hello, and welcome to my guestbook, because it's 1997!</p>

        <ul class="guests">
            <li>...</li>
        </ul>
       <img src="image.png">
    {{ end }}

code:(main.go some part)

var index = template.Must(template.ParseFiles(
  "templates/_base.html",
  "templates/index.html",
))

func hello(w http.ResponseWriter, req *http.Request) {
  if err := index.Execute(w, nil); err != nil {
      http.Error(w, err.Error(), http.StatusInternalServerError)
  }
}

func main(){ etc...
web application work fine. but image didnt show

  • 写回答

2条回答 默认 最新

  • dongming5444 2014-11-19 07:04
    关注

    Open your web browser and see what's the request to that image resource is returning.

    It's probably returning a 404 Not Found because it can't locate the file.

    For example in Chrome that would be:

    image resource chrome developer tools

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向