beego can not find the template file

Created on 4 Jun 2013  ·  20Comments  ·  Source: astaxie/beego

when i run an empty app that created with bee. it told me that beego:can't find templatefile in the path:index.tpl

i run the app with "go run main.go"

Most helpful comment

IDE工具默认将二进制编译到一个临时目录,比如Win IDEA编译的时候就是这样:
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin\runnerw.exe" C:/Go\bin\go.exe build -o "C:\Users\youzhengchuan\AppData\Local\Temp\Build main.go and rungo" C:/Users/youzhengchuan/Documents/myGolangProject/src/myWebProject2/main.go

那么运行的时候,二进制当然找不到相对路径的 index.tpl了,修改下IDE工具的设置,选择编译输出目录为 $GOPATH/src/$UBEEGOPROJECT/ 即可。

All 20 comments

go run的原理你先了解一下,为啥找不到?

go run means go build && ./xxx

i don't see the difference

go run之后的可运行文件在哪里呢?在你当前的目录下吗?

I'm seeing the exact same thing on OS X. Makes no difference whether I build and run the executable or I use 'go run main.go'. I've also tried explicitly setting beego.ViewsPath and it's made no difference, still not working. The exact same code works fine on a Windows machine.

Seems to be something to do with the views folder not being found. BeeTemplates is empty at all times.

I just ran into this, and cannot tell what is going on exactly because I'm just playing & learning with go. I'm not sure if it is beego or has to do with gvm(go version manager)

with this:

https://gist.github.com/anonymous/5744693

I get this trace at the root:

site_name:can't find templatefile in the path:index.html
Request Method:     GET
Request URL:    /
RemoteAddr:     127.0.0.1:55622
Stack

/home/.gvm/gos/go1.1/src/pkg/runtime/panic.c 229
/home/.gvm/pkgsets/go1.1/global/src/github.com/astaxie/beego/controller.go 187
/home/.gvm/pkgsets/go1.1/global/src/github.com/astaxie/beego/controller.go 100
/home/.gvm/gos/go1.1/src/pkg/reflect/value.go 474
/home/.gvm/gos/go1.1/src/pkg/reflect/value.go 345
/home/.gvm/pkgsets/go1.1/global/src/github.com/astaxie/beego/router.go 389
/home/.gvm/gos/go1.1/src/pkg/net/http/server.go 1517
/home/.gvm/gos/go1.1/src/pkg/net/http/server.go 1096
/home/.gvm/gos/go1.1/src/pkg/runtime/proc.c 1223

I added os.Getwd() to my file to find out where I was and ended up with this:

/tmp/go-build637664304/command-line-arguments/_obj/exe

and in that directory is the directory log with the logfile in it

So for some reason, it is run in this tmp directory and I'm not sure it is because of beego or has to do with gvm or what because I still don't have a lot of go experience.

edit:

I did a simple hello world within the same gvm instance and it printed out the working directory as

/home/None/gohw

which is the directory where I did 'go run gohw.go'

So, beego seems go to /tmp/go-build637664304/command-line-arguments/_obj/exe for something and doesn't come back, or is this standard go behavior, or what?

edit2:

apparently, 'go run file.go' isn't the way to do it.

  1. go build
  2. ./file (if your main is in file.go)

http://stackoverflow.com/questions/17014329/why-is-tmp-go-build644681611-command-line-arguments-obj-exe-passed-in-to-go-ru

first you should know go run is running the application in the tmp files. For example when you run the shell go run xxx.go, the running file in the tmp file. While beego will find the template file from the same dir. So you will get some error that you can't find the template file.

so if you want to run you code correct. you should do like this

  1. go into the app dir then run the shell go build
  2. then run the application ./beegoapp

i use go build, it still report this error.

Sent from my Gmail

On 2013-6-11, at ÏÂÎç11:38, astaxie [email protected] wrote:

first you should know go run is running the application in the tmp files. For example when you run the shell go run xxx.go, the running file in the tmp file. While beego will find the template file from the same dir. So you will get some error that you can't find the template file.

so if you want to run you code correct. you should do like this

go into the app dir then run the shell go build 2.then run the application ./beegoapp
¡ª
Reply to this email directly or view it on GitHub.

how did u do it?

show me the code and error completly

i reinstall the beego and create a new project. i works now.

By {thrisp}

apparently, 'go run file.go' isn't the way to do it.

go build

./file (if your main is in file.go)

1.创建并编译web项目(cmd中注意项目路径)
bee new myproject
go build main.go
2.在web项目目录下找到编译好的main.exe 文件双击运行
3.浏览器输入:http://localhost:8080/
4.如果呈现Welcome to Beego!页面,那么你就成功了。
提示,在sublime软件中执行go run main.go命令,然后访问页面就会出现这个错误,如果哪位知道是什么原因请告之。

Don't use "go run mainfile.go" command while using beego.. Try "bee run projectname"..

IDE工具默认将二进制编译到一个临时目录,比如Win IDEA编译的时候就是这样:
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.3\bin\runnerw.exe" C:/Go\bin\go.exe build -o "C:\Users\youzhengchuan\AppData\Local\Temp\Build main.go and rungo" C:/Users/youzhengchuan/Documents/myGolangProject/src/myWebProject2/main.go

那么运行的时候,二进制当然找不到相对路径的 index.tpl了,修改下IDE工具的设置,选择编译输出目录为 $GOPATH/src/$UBEEGOPROJECT/ 即可。

碰到同样的问题,出错的地方应该是在于运行的二进制文件的路径跟模板存放的路径不一样,所以根据相对路径寻找模板文件的时候会找不到文件。正确的做法是将二进制文件移动到对应模板文件的目录,或者在IDE中设置好工作路径。不如在goland可以设置 working directory 为views所在的路径。

beego:can't find templatefile in the path:welcome.html
Request Method: | GET
-- | --
Request URL: | /
RemoteAddr: | 127.0.0.1

I used IDE Goland to run and debug the app of Beego and I found the same error above. I changed the IDE output directory to the same directory of the main.go, and it compiled successfully!!

@503718696 只需将views放置在$GOPATH下即可找到页面

@503718696 只需将views放置在$GOPATH下即可找到页面

试了的确好用,但是这是bee生成的demo项目,一开始是跑起来的莫名其妙就跑不起来了 试了你这个方法 可以跑了

如果你想点击 工具栏的运行按钮直接 运行项目 那么就得把views 放在$GOPATH下面 ,否则会报错这个文件找不到。 如果你是用 命令行 运行项目 src cd quickstart quickstart bee run 你就又得把 view放在quickstart 项目名下面 否则也会报错。我试了一遍是这样的

在这里还应该注意的是:
比如你的项目在 GOPATH/src/Demo
你应该把go build -o demo.exe Demo好的可执行程序放到你的 GOPATH/src/Demo 下,
并且你在shell 中去执行 ./demo.exe 的之后你当前shell 也必须要在 GOPATH/src/Demo 下面,不然也会找不到模版文件。

在这里还应该注意的是:
比如你的项目在 GOPATH/src/Demo
你应该把go build -o demo.exe Demo好的可执行程序放到你的 GOPATH/src/Demo 下,
并且你在shell 中去执行 ./demo.exe 的之后你当前shell 也必须要在 GOPATH/src/Demo 下面,不然也会找不到模版文件。

终于解决我的问题了,谢谢。“当前shell也要在 GOPATH/src/Demo 下面!!!”

Was this page helpful?
0 / 5 - 0 ratings