GAE:如何上传要由应用程序访问的文件? [英] GAE: How to upload files to be accessed by the application?

查看:92
本文介绍了GAE:如何上传要由应用程序访问的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我发现问题。即使它们位于子目录中,我的HTML文件静态规则仍与模板匹配。在改变规则以不再匹配它们之后,应用程序就可以访问这些文件。



我正在创建一个Google AppEngine应用程序。我正在使用Go语言,但我不确定这是相关的。我想要使​​用带有单独模板文件的模板。所以应用程序必须读取模板文件。在本地这可以工作,但在将应用程序上传到GAE后,当调用template.ParseFiles()时,我得到没有这样的文件或目录。

所以我想,我必须指出模板文件是应用程序文件,以便以正确的方式上传。我想也许我的模板文件被上传为静态文件,因为这在我的app.yaml

   -  url:/(.* \.html)
static_files:\ 1
upload:。* \.html

所以我把它们移到他们自己的目录中。但是这并没有什么区别。我尝试在app.yaml中为我的脚本规则添加上传指令,如下所示:

   -  url:/.* 
脚本:_go_app
上传:模板/.*

但似乎没有被)允许。那么谁能告诉我如何从我的GAE应用程序访问模板文件(或任何数据文件)?



谢谢!

假定它们不在 static_dir 中,或者 static_files 目录。请参阅App Engine文档中的跳过文件部分。 App Engine将这些目录和文件视为静态资源,并分别提供静态资源。应用程序代码通常无法访问静态资源。



静态资源通常无法从应用程序代码访问。如果您必须将您的模板放在与其他静态资源相同的目录中,则可以使用 application_readable 设置为应用程序访问此类资源。



但是,正如你所注意到的,你可以将你的模板放在你的应用程序中没有映射到静态资源路径的地方;这可能是正确的做法。


Update: I found the problem. My static rule for HTML files still matched the templates even though they were in a subdirectory. After changing the rule to not match them anymore, the files could be accessed by the application.

I'm creating a Google AppEngine application. I'm using the Go language but I'm not sure that's relevant. I want to use a template with a separate template file. So the application must read the template file. Locally this works but after uploading the app to GAE, I get "no such file or directory" when calling template.ParseFiles().

So I'm thinking that somehow I must indicate that the template files are application files so that they get uploaded in the right way. I thought maybe my template files were uploaded as static files because of this in my app.yaml

- url: /(.*\.html)
  static_files: \1
  upload: .*\.html

So I moved them to their own directory. But that didn't make a difference. I tried adding an upload directive for my script rule in app.yaml like this:

- url: /.*
  script: _go_app
  upload: templates/.*

But that didn't seem to be allowed. So can anyone tell me how do I access the template files (or any data files) from my GAE application?

Thanks!

解决方案

The files are automatically uploaded, assuming they're not in a static_dir or static_files directory. See the Skipping Files section in the App Engine documentation. App Engine treats such directories and files as static resources, and static resources are served separately from the application.

Static resources are not normally accessible from application code. If you must put your templates in the same directory as your other static resources, you can use the application_readable setting to make such resources accessible to your app as well.

But as you note, you can put your templates in a place within your app that isn't mapped to a static resource path; that's probably the right thing to do.

这篇关于GAE:如何上传要由应用程序访问的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆