0

我正在尝试只渲染一个模板:

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
}

但我有错误not a directory。我的exist功能:

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

    return true
}

它返回true。有什么问题template.ParseFiles?我看到了文档,并且在哪里写了论点filenamesThere must be at least one file. 我做错了什么?

编辑: 我的变量:

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

我的文件内容:

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

编辑2:我已经将我所有的项目、库等移到了/home/cnaize/gocode,现在我有错误:

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

Revel问题吗?我该怎么办?我试图删除这个 bin 文件,没有帮助。

4

1 回答 1

2

实际问题是文件夹中的路径Dropbox/:考虑到它是由外部进程同步/管理的(dropbox),访问文件的能力并不总是可靠的。

将文件放在 Dropbox 路径之外可以解决问题。

于 2014-07-15T06:25:08.517 回答