douwei8911 2016-05-25 10:45
浏览 53

转到Google App引擎-找不到模板文件

I using Gin framework. At local development mode: goapp serve all works fine.

func init() {
    route := gin.Default()
    route.LoadHTMLGlob("../*/views/**/*.html")
    ...
}

But after deploy:

panic: html/template: pattern matches no files: ../*/views/**/*.html

OK. I try:

func init() {
    route := gin.Default()
    dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
    route.LoadHTMLGlob(dir + "/../*/views/**/*.html")
    ...
}

Same result.

I try fetch dir:

...
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
    ...
}
c.String(http.StatusOK, "Dir: ", dir)

c.String(http.StatusOK, "
OK")
res, err := filepath.Glob(dir + "/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v

", res, err))

c.String(http.StatusOK, "Dirs:")
res, err = filepath.Glob(dir + "/**/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v", res, err))
...

Result:

Dir: %!(EXTRA string=/base/data/home/apps/tmp-LEIYJC/_ah) OK[/base/data/home/apps/tmp-LEIYJC/_ah/exe] |

Dirs:[] |

Ooops. What I done wrong?

UPD:

app.yaml

runtime: go
api_version: go1

handlers:
- url: /images
  static_dir: ../static/images

- url: /css
  static_dir: ../static/css

- url: /js
  static_dir: ../static/js

- url: /fonts
  static_dir: ../static/fonts

- url: /.*
  script: _go_app

I put app.yaml to subdirectory, cause without that another problem: [https://groups.google.com/forum/#!topic/google-appengine-go/dNhqV6PBqVc

Folder structure:

app/
    app.go
    app.yaml
static/
    ...
frontend/
controllers/
    UserController.go
    ...
models/
    UserModel.go
    ...
views/
        home/
            *.html
        user/
            *.html
        anotherfolder/
            *.html
backend/
controllers/
    MainController.go
    ...
models/
    SomeModel.go
    ...
views/
        main/
            *.html
        anotherfolder/
            *.html
...
  • 写回答

2条回答 默认 最新

  • dqwh1203 2016-05-25 20:26
    关注

    If I'm not mistaken all of your directories should live within the root directory where your app.yaml exists. So you would want something like this. Also, when you want your application to access a static file directory you need to add application_readable: true to that directories definition. See the next example down. Hope this helps.

    app/
        app.go
        app.yaml
        static/
            ...
        frontend/views/
            home/
            *.html
        anotherfolder/
            *.html
    

    Example Directory Definition:

    - url: /s
      static_dir: s/
      application_readable: true
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题