google-app-engine – 使用App Engine提供静态文件

栏目: 后端 · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/5609000/serve-static-file-using-app-engine
我创建了一个App Engine应用程序.到目前为止,我只提供了几个HTML文件.只要有人访问了 http://example.appengine.com/

,我可以做什么来让App Engine提供index.html文件?

目前,我的app.yaml文件如下所示:

application: appname
version: 1
runtime: python
api_version: 1

handlers:

- url: /
  static_dir: static_files

这应该做你所需要的:

https://gist.github.com/873098

说明:在App Engine Python中,可以使用正则表达式作为app.yaml中的URL处理程序,并将所有URL重定向到静态文件的层次结构.

示例app.yaml:

application: your-app-name-here
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.css)
  mime_type: text/css
  static_files: static/\1
  upload: static/(.*\.css)

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

- url: /(.*\.js)
  mime_type: text/javascript
  static_files: static/\1
  upload: static/(.*\.js)

- url: /(.*\.txt)
  mime_type: text/plain
  static_files: static/\1
  upload: static/(.*\.txt)

- url: /(.*\.xml)
  mime_type: application/xml
  static_files: static/\1
  upload: static/(.*\.xml)

# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
  static_files: static/\1
  upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))

# index files
- url: /(.+)/
  static_files: static/\1/index.html
  upload: static/(.+)/index.html

# redirect to 'url + /index.html' url.
- url: /(.+)
  static_files: static/redirector.html
  upload: static/redirector.html

# site root
- url: /
  static_files: static/index.html
  upload: static/index.html

为了处理不以识别类型(.html,.png等)结尾的网址的请求或/您需要将这些请求重定向到URL /,因此该目录的index.html已被提供.我不知道在app.yaml中有什么办法,所以我添加了一个javascript重定向器.这也可以用一个很小的 python 处理程序来完成.

redirector.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script language="JavaScript">
      self.location=self.location + "/";
    </script>
  </head>
  <body>
  </body>
</html>

http://stackoverflow.com/questions/5609000/serve-static-file-using-app-engine


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Just My Type

Just My Type

Simon Garfield / Profile Books / 2010-10-21 / GBP 14.99

What's your type? Suddenly everyone's obsessed with fonts. Whether you're enraged by Ikea's Verdanagate, want to know what the Beach Boys have in common with easy Jet or why it's okay to like Comic Sa......一起来看看 《Just My Type》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换