dsqdpn31467 2014-07-15 06:05
浏览 249
已采纳

Golang template.ParseFiles“不是目录”错误

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条回答 默认 最新

  • dongmiyi8220 2014-07-15 06:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面