Google App Engine 的应用缓存清单

1 投票
1 回答
609 浏览
提问于 2025-04-18 12:30

我正在尝试制作一个基本的应用程序,让我的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

我找到了!我需要在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"

撰写回答