我很确定我忽略了一些显而易见的事情,但我不确定是什么.我正在构建一个简单的Web应用程序,提供模板化的书籍页面.模板工作正常,图像的路径似乎正确填充,但我不断为图像本身收到404错误.
这是模板:
<h1>{{.Title}}</h1>
<h2>{{.Author.Name}}</h2>
<image src="../images/{{.ImageURI}}" />
Run Code Online (Sandbox Code Playgroud)
这是应用程序本身:
package main
import (
"html/template"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/user/marketplace/typelibrary"
)
var books []typelibrary.Book
func ItemHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
var selected typelibrary.Book
//Retrieve item data
for _, item := range books {
if item.ID == params["id"] {
selected = item
break
}
}
t, _ := template.ParseFiles("./templates/book.html")
t.Execute(w, selected)
}
func main() {
router := mux.NewRouter()
books = append(books, typelibrary.Book{ID: "1", Title: "The Fellowship of the Ring", ImageURI: …Run Code Online (Sandbox Code Playgroud)