templates - Golang 模板.ParseFiles "not a directory"错误

标签 templates go revel

我试图只渲染一个模板:

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
}

它返回 truetemplate.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 文件,但没有帮助。

最佳答案

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

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

关于templates - Golang 模板.ParseFiles "not a directory"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750896/

相关文章:

c++ - 模板参数无效

c++ - 缩短 C++ 函数签名的标准方法

asp.net - 如何将图像插入电子邮件模板

使用 govendor、dh-make-golang 构建 Go 1.7 项目时 Go 导入 vendor 依赖项问题

linux - 如何使用 Golang 安装 Gin

c++ - 对具有 C++ 模板方法的函数的 undefined reference

function - Go - void函数和直接赋值

去 : model ( or interface ) function with input of different types

go - 无法在 MacOS 上安装 Revel "package gopkg.in/fsnotify.v1: unrecognized import path"

templates - 尝试将参数传递给 url 时索引超出范围