【问题标题】:how to serve static files on google app engine如何在谷歌应用引擎上提供静态文件
【发布时间】:2013-07-28 11:54:17
【问题描述】:

基本上我是谷歌应用引擎的新手,我有一个名为模板的文件夹,其中有几个文件:

index.php
result.php
request.php

但是,在 yaml.app 上,我只知道如何通过将 templates/index.php 设为默认页面来在本地运行服务器。 我的意思是当我去http://localhost:8080 时,这就是我所看到的。但是当我做http://localhost:8080/templates/index.php 时,它说找不到 404。 如何在我的应用程序内的任何目录中使用我想要的所有文件,这是我应该添加到我的 app.yaml 的某种规则吗?

这是当前使用的 app.yaml:

application: sympy-live-hrd
version: 38

runtime: python27
threadsafe: true
api_version: 1

libraries:
- name: numpy
  version: latest
- name: matplotlib
  version: latest

handlers:
- url: /static
  static_dir: static
  expiration: 1d

# cache-busting scheme
# request /static-(app version)/filename
- url: /static-[0-9]+/(.*)
  static_files: static/\1
  upload: static/(.*)

# if you're adding the shell to your own app, change this regex url to the URL
# endpoint where you want the shell to run, e.g. /shell . You'll also probably
# want to add login: admin to restrict to admins only.
- url: .*
  script: shell.application

Shell.application 是一个 python 脚本,我编辑它以使用 templates/index.php 作为默认值

【问题讨论】:

  • 我已经红了那个文档,但我仍然对如何实现它感到困惑。
  • 什么感到困惑?
  • 关于 url 处理的工作原理,我将我当前的 app.yaml 添加到问题中。
  • 如果文件在 templates 目录中,那么static_dir 应该是static_dir: templates

标签: php python google-app-engine


【解决方案1】:

我假设 index.php 是一个脚本?

我相信您必须使用 php 运行时运行 php 脚本。它们不会从 python 运行时作为脚本运行,因此首先,您将无法运行 php 脚本。

其次,您需要一个指向您的模板文件夹的处理程序,但它不存在。

handlers:
- url: /templates
  static_dir: templates
  expiration: 1d

请注意,这只会加载文件,除非您使用 php 运行时,否则它不会运行 php 文件。

【讨论】:

  • 是的,我修复了处理程序部分,正如您所说,php 文件没有被加载而是被下载。我不能同时运行python和php吗?
  • 好像不行,你应该提到你要使用的运行时
  • 查看新的模块功能。应用程序中的不同模块可以运行不同的运行时,但任何单个实例只能运行一个运行时。 developers.google.com/appengine/docs/python/modules 你想要做的应该是可能的,但你需要在处理 php url 的 php 运行时模块中设置你的 php 代码。
  • 谢谢!这实际上是让我工作的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
  • 2011-03-11
  • 1970-01-01
相关资源
最近更新 更多