Python 使用Google应用程序引擎的应用程序缓存清单
我正在尝试制作一个基本的应用程序,使我的index.html文件在没有互联网的情况下离线运行。我正在使用谷歌应用程序引擎、Webapp2和Jinja2。你能为离线网站/网络应用推荐一个更好的框架吗 运行此应用程序时,出现以下控制台错误:Python 使用Google应用程序引擎的应用程序缓存清单,python,google-app-engine,jinja2,webapp2,cache-manifest,Python,Google App Engine,Jinja2,Webapp2,Cache Manifest,我正在尝试制作一个基本的应用程序,使我的index.html文件在没有互联网的情况下离线运行。我正在使用谷歌应用程序引擎、Webapp2和Jinja2。你能为离线网站/网络应用推荐一个更好的框架吗 运行此应用程序时,出现以下控制台错误: Creating Application Cache with manifest http://localhost:9080/static/cache.manifest localhost/:1 Application Cache Checking event
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>
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"
应用程序yaml
<!DOCTYPE html>
<html manifest="/static/cache.manifest">
<head>
</head>
<body>
Hello World
</body>
</html>
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"
我找到了!我需要在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"