How to open a html document with template engine in golang

Hello guys,
I try to open an HTML document for the login page. when trying with this section I got this error :

func Index(response http.ResponseWriter, request *http.Request) {

tmp, err := template.ParseFiles("")
if err != nil {

tmp.Execute(response, nil)


I got os.PathError

and the HTML document is under this path:
– root path project

I think this problem is for the path that I gave to template.ParseFiles. but I don’t know how I must give the correct path to ParseFiles. may please guide me. thank you

I update path for ParseFiles to : tmp, err := template.ParseFiles("pkg/web/templates/admin/index.html")

and now HTML document loaded, but CSS and javascript won’t load. shall I do something else?

You have to point to CSS and JS folders as well. And all other folders that you use.

http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./public/css"))))

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.