html - CSS and images from a different folder are not read when rendering template using Golang -
i trying render template using html/template module of golang. css files , images same folder page rendering executed, located in different folder ignored. here code:
func render(w http.responsewriter, filename string, data interface{}) { tmpl, err := template.parsefiles(filename) if err != nil { http.error(w, err.error(), http.statusinternalservererror) } if err := tmpl.execute(w, data); err != nil { http.error(w, err.error(), http.statusinternalservererror) } }
for page example:
<head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>start connect</title> <link href="../css/bootstrap.min.css" rel="stylesheet"> <link href="one-page.css" rel="stylesheet"> </head>
the one-page.css executed not bootstrap.
using ../css
on web should avoided , error source. go server cannot resolve file (because don't have handler ../css
uri). should change ../css
part /css
, tell server (you didn't provide details, cannot show code) handle /css
uris serving files.
assuming using default net/http
mux, code should like:
mux := http.newservemux() mux.handle("/css/", http.stripprefix("/css/", http.fileserver(http.dir("css")))) http.listenandserve(":8080", mux)
Comments
Post a Comment