i can display only image writing on main.go (parsefile).
but writing on html image didnt show.
我试过html / template。它也没有用。
代码:_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 }}
代码:( 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 ...
网络应用工作正常。但是图像没有显示
答案 0 :(得分:3)
打开您的网络浏览器,看看该图片资源的请求是什么。
它可能会返回404 Not Found
,因为它无法找到该文件。
例如在Chrome中可能是:
答案 1 :(得分:1)