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.

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

报告相同问题?

悬赏问题

  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置