英文:
Golang template.ParseFiles "not a directory" error
问题
我正在尝试渲染一个模板:
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
有什么问题?我查看了文档,上面写着参数应该是文件名
,并且至少要有一个文件
。我做错了什么?
编辑:
我的变量:
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文件,但没有帮助。
英文:
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
得分: 2
实际问题是Dropbox/
文件夹内的路径:考虑到它是由外部进程(dropbox
)同步/管理的,访问该文件的能力并不总是可靠的。
将文件放在Dropbox路径之外可以解决这个问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论