我正试图使一个基本的应用程序,将使我的index.html文件离线运行-当没有互联网可用。我正在使用谷歌应用引擎,Webapp2和Jinja2。你会建议一个更好的框架离线网站/web应用程序。
当我运行这个应用程序时,我得到这个控制台错误:
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"
我找到了!我需要在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"