Golang template.ParseFiles “not a directory” error

2019-06-12 05:05发布

问题:

I'm trying to render just one template:

root_path, err := osext.Executable()
if err != nil {
    return err
}
template_path := root_path + "/app/views/mailtemplates/" + "feedback.html"

fmt.Println(exist(template_path))

tmpl, err := template.ParseFiles(template_path)
if err != nil {
    return err
}

but I have the error not a directory. My exist function:

func exist(file_path string) bool {
    if _, err := os.Stat(file_path); os.IsNotExist(err) {
        return false
    }

    return true
}

it returns true. What's the problem with template.ParseFiles? I see documentation and where written that arguments are filenames and There must be at least one file. What I doing wrong?

EDITED: My variables:

root_path: /home/cnaize/Dropbox/develop/gocode/bin/advorts
template_path: /home/cnaize/Dropbox/develop/gocode/bin/advorts/app/views/mailtemplates/feedback.html

My file's content:

<html>
    <head>
    </head>
    <body>
        Hello, World!
    </body>
</html>

EDITED 2: I've moved all my projects, libs and etc to /home/cnaize/gocode and now I have error:

open /home/cnaize/gocode/bin/advorts/app/views/mailtemplates/feedback.txt: not a directory

Is it Revel's problem? What I supposed to do? I've tried to remove this bin file, didn't helped.

回答1:

The actual issue was a path within the Dropbox/ folder: consider it is synchronized/managed by an external process (dropbox), the ability to access the file isn't always reliable.

Putting the file outside of that Dropbox path would solve the issue.