- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在开发一个 Google App Engine Go 应用程序,需要在我的一个包中使用一些 HTML 模板。当前文件结构为:
GOPATH/github.com/NAME/PROJECT/
app/
app.go
app.yaml
package/
package.go
Templates/
Template.html
为了包含这个包,我使用:
导入“github.com/NAME/PROJECT/package”
在 package.go 内部,我尝试以各种方式解析我的 Template.html 文件:
//Template, err := template.ParseFiles("package/Templates/Template.html") //doesn't work - "The system cannot find the path specified."
//Template, err := template.ParseFiles("github.com/NAME/PROJECT/package/Templates/Template.html") //doesn't work - "The system cannot find the path specified."
//Template, err := template.ParseFiles("Templates/Template.html") //doesn't work - "The system cannot find the path specified."
//Template, err := template.ParseFiles("/Templates/Template.html") //doesn't work - "The system cannot find the path specified."
Template, err := template.ParseFiles("../package/Templates/Template.html") //works on desktop!
因此,我选择了适用于我的桌面测试环境的最后一个选项,将其上传到 AppEngine,然后我收到了“不允许操作”的新错误...
如何使用如上所示的文件配置解析 HTML 模板,使其同时适用于 App Engine 和桌面?
最佳答案
您需要在应用程序的根目录下安装 app.yaml
。 App Engine 使用 app.yaml
的位置来确定哪些文件与您的应用程序关联。您想要将此文件移动到顶层。
例如,假设我们有这样的东西:
app.go
app.yaml
templates/t1
templates/t2
app.yaml 是您的应用程序通常具有的内容,app.go 是:
package app
import (
"html/template"
"net/http"
)
var templates = template.Must(template.ParseGlob("templates/*"))
func init() {
http.HandleFunc("/", rootHandler)
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[1:] // drop the leading slash
tmpl := templates.Lookup(name)
if tmpl == nil {
http.NotFound(w, r)
return
}
tmpl.Execute(w, nil)
}
和templates/t1
和templates/t2
是合适的模板文件。一旦我们有了这个,我们就可以访问生成的 web 应用程序中的 t1/
和 t2/
,它应该可以在 App Engine 上正常服务和部署。
关键是将 app.yaml
放在应用程序的顶层目录中。另一个要记住的注意事项:确保您尝试从动态应用程序读取的任何文件都不是静态提供或跳过的。检查您的 app.yaml
。如果要静态提供文件,那么通常只允许前端查看该文件,这意味着您的后端不会。跳过的文件在部署期间会被完全忽略。
关于html - 模板解析错误 - "operation not permitted",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131274/
我试图设置 POSIX 消息队列的大小,但似乎不被允许。 msgctl() 手册页指出: IPC_SET can only be executed by a process with appropri
好的,我在尝试对 MOV 文件进行编码时收到“av_interleaved_write_frame(): Operation not allowed”错误。首先,我需要概述其背后的条件。 我通过在 c
我有一个运行带有选项 allow_other 和 umask 0 的 fuse fs。这给了我一组权限设置为 777 的文件。虽然当我尝试 ls -l 时在包含文件的目录中,我得到以下输出: ls:
我已经安装了 JENKINS 并创建了一个 bob,但是作业因以下错误而失败。我尝试了很多方法,例如授予权限,但都无法使其运行。 谁能告诉我可能是什么原因以及如何让它运行。 13:45:49 Star
我有这行简单的代码: mkdir($path_to_rpi, 0755); chgrp($path_to_rpi, 'sambashare'); 目录创建为 www-data
我是初学者。我尝试使用 git 创建用户名。但是当我打字的时候 git config --global user.name "XXX" 消息显示 Unable to read current work
我的代码如下: calcstep ::Integral a => a -> a calcstep n = calcstep2 n 0 calcstep2 :: Integral (Integral
我们正在gitlab CI中的Alpine Docker镜像中运行vault-cli。 升级后,在调用保管库时会得到以下信息: /bin/bash: line 117: /usr/sbin/vault
在 WinSCP 中,如果您从本地服务器打开了一个文件,并进行更改并按 (Ctrl + S),基本上保存它,您会得到错误提示: /path of the file/ set times: Operat
尽管使用 sudo,pip install 命令有时会生成类似于以下内容的错误: ...Installing collected packages: setuptools, protobuf, whe
我的任务是为系统上的所有用户列出用户所属的所有组。这个想法是通过 /etc/passwd 并为每个用户打印其组。 [编辑] 成功了: if( getgrouplist(passwd->pw_name,
我正在研究 UNIX 网络编程中的示例,并且我已将“daytimeclientcli.c”改编为此处特定于 linux 的代码(这些示例使用 BSD)。我在 here 上针对时间服务器运行了该程序.无
import config from flask import Flask from flask_redis import Redis from werkzeug.contrib.fixers imp
HugeTLB - Large Page Support in the Linux Kernel #include #include #include #include #define MB_
我正在开发一个 Google App Engine Go 应用程序,需要在我的一个包中使用一些 HTML 模板。当前文件结构为: GOPATH/github.com/NAME/PROJECT/
我正在使用 isolate ,一个隔离器,用于隔离另一个使用 Linux 容器的程序的执行。它非常方便,并且在我的本地计算机上运行良好(我可以运行 fork 炸弹和无限循环,它可以保护一切)。 现在我
我正在尝试在用户空间中使用 mmap 来读取“mem_map”开始的物理内存。它是一个包含所有物理页面的数组。这是一台运行 3.0 内核的 i386 机器。 代码是这样的: .... //define
我有问题,我需要通过 php 脚本为系统中的不同用户设置文件所有者权限 所以我通过以下命令执行此操作,其中 1002 是系统的用户 ID。 file_put_contents($filename, $
在拉取一些 docker 镜像(但不是全部)时出现此错误: failed to register layer: Error processing tar file(exit status 1): op
我有一个带有 Rails API 的 React SPA。我最近更改了 React 端的 API 请求以通过 axios 而不是 jquery,我的 axios 设置是: export default
我是一名优秀的程序员,十分优秀!