我试图只渲染一个模板:
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
。
我的存在
函数:
func exist(file_path string) bool {
if _, err := os.Stat(file_path); os.IsNotExist(err) {
return false
}
return true
}
它返回 true
。 template.ParseFiles
有什么问题?我看到文档,其中写到参数是 filenames
和 There 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 文件,但没有帮助。
最佳答案
实际问题是 Dropbox/
文件夹中的路径:考虑到它是由外部进程 (dropbox
) 同步/管理的,访问文件的能力是'始终可靠。
将文件放在该 Dropbox 路径之外可以解决问题。
关于templates - Golang 模板.ParseFiles "not a directory"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750896/