使用Google App Engine的应用程序缓存清单

时间:2014-07-08 14:06:33

标签: python google-app-engine jinja2 webapp2 cache-manifest

我正在尝试创建一个基本应用程序,使我的index.html文件脱机运行 - 当没有可用的互联网时。我正在使用Google App Engine,Webapp2和Jinja2。您是否会为离线网站/网络应用建议一个更好的框架。

当我运行此应用程序时,我收到此控制台错误:

Creating Application Cache with manifest http://localhost:9080/static/cache.manifest localhost/:1
Application Cache Checking event localhost/:1
Application Cache Downloading event localhost/:1
Application Cache Progress event (0 of 1) http://localhost:9080/index.html localhost/:1
Application Cache Error event: Resource fetch failed (404) http://localhost:9080/index.html 

我使用了以下内容:

文件

static/cache.manifest
main.py
index.html
app.yaml

main.py

import os, webapp2, jinja2

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class Home(webapp2.RequestHandler):
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render())

app = webapp2.WSGIApplication([('/', Home),
                              ], debug=True)

的index.html

<!DOCTYPE html>
<html manifest="/static/cache.manifest">
    <head>
    </head>
    <body>
        Hello World
    </body>
</html>

cache.manifest

CACHE MANIFEST
/index.html

的app.yaml

application: formetoteston
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static/(.*\.(appcache|manifest))
  mime_type: text/cache-manifest
  static_files: static/\1
  upload: /static/(.*\.(appcache|manifest))
  expiration: "0m"

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

- name: jinja2
  version: "2.6"

1 个答案:

答案 0 :(得分:0)

我找到了!我需要在app.yaml中添加正确的URL处理程序。除了我将index.html移动到/ static。

application: formetoteston
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: static/(cache.manifest)
  mime_type: text/cache-manifest
  static_files: static/cache.manifest
  upload: static/(cache.manifest)

- url: static/(.*)
  static_files: static/index.html
  upload: static/index.html

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

- name: jinja2
  version: "2.6"