【发布时间】:2015-02-19 08:51:12
【问题描述】:
我现在有很多关于app.yaml的问题,找了又找,但是没找到这个。
TLDR:请先阅读完整答案,这不是您的标准 application_readable:true。 我基本上想通过不同的路径访问同一个文件,例如/static/img/pic.jpg 和 /img/pic.jpg
用例
我构建了一个烧瓶应用程序(基于 fsouza 的工作),我尝试构建一个适用于 gae 的烧瓶缩略图扩展(因为它是一个只读 FS,我分叉了 flask-thumbnails 并且目前尝试展开它。)
所以我需要:
- 通过 python 访问我的静态文件,以便我可以读取 img 并即时制作缩略图。 网址是例如。 /STATIC/IMG/PIC.JPG
- 仍然通过 app.yaml 传递其他图片、css、js。 网址是例如。 /IMG/PIC.JPG
什么不工作:
它在本地工作,部署后将无法工作。我认为 app.yaml 并没有像应该的那样被 dev_appserver.py 严格执行。
我可以让其中一种方案发挥作用。这是我的 app.yaml 目前的样子:
builtins:
- appstats: on
- admin_redirect: on
- deferred: on
- remote_api: on
- url: /css
static_dir: application/static/css
- url: /js
static_dir: application/static/js
- url: /img
static_dir: application/static/img
- url: /static
static_dir: application/static
application_readable: true
- url: .*
script: run.application.app
我也试过这个:
- url: /css/(.*)
static_files: css/\1
upload: css/(.*)
- url: /js/(.*)
static_files: js/\1
upload: js/(.*)
- url: /img/(.*)
static_files: img/\1
upload: img/(.*)
当我注释掉特定的 js,css,img 内容时,应用程序可以访问 application/static/img 中的 img 并从中制作缩略图。但是带有例如的网址不会提供 /img/dont.need.thumbnail.jpg。
当我评论这部分时:
- url: /static
static_dir: application/static
application_readable: true
img,css,js 得到应有的服务。
有人可以帮我吗?我做错了什么?
app.yaml url 是递归的吗?
当前解决方法:
我目前的解决方法是,我只需在 python 应用程序中添加几个 url 路由。但这效率不高,我怀疑它会花费我更多的 CPU 时间并且速度更慢。 例如
app.add_url_rule('/img/<path>', 'static_img_files', view_func=views.static_img_files)
def static_img_files(path):
return static_files("img/"+path)
奖励提示:
如果你只是 git push-to-deploy
application_readable: true
不会工作,因此一旦您在 gae 服务器上测试它,python 应用程序就无法访问静态图像,而不再是本地。你必须通过应用引擎启动器来部署它(仅这一点我花了很长时间才发现)
【问题讨论】:
标签: python google-app-engine app.yaml google-app-engine-python