0

我面临与谷歌应用引擎应用程序相同的问题。它适用于 SDK(本地主机),上传到 appengine 时不起作用。部署成功。我被困在这个上了!!!任何帮助表示赞赏。

回溯日志如下:

    Traceback (most recent call last):
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~cloud-chess/1.368562751153844474/chessboard.py", line 29, in get
    template = JINJA_ENVIRONMENT.get_template('files/html/chess.html')
  File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/environment.py", line 719, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/environment.py", line 693, in _load_template
    template = self.loader.load(self, name, globals)
  File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/loaders.py", line 115, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/python27_runtime/python27_lib/versions/third_party/jinja2-2.6/jinja2/loaders.py", line 180, in get_source
    raise TemplateNotFound(template)
TemplateNotFound: files/html/chess.html

部署日志:

01:56 PM Host: appengine.google.com
01:56 PM Application: cloud-chess; version: 2
01:56 PM 
Starting update of app: cloud-chess, version: 2
01:56 PM Getting current resource limits.
Password for xxxx.pk@gmail.com: 01:56 PM Scanning files on local disk.
01:56 PM Cloning 17 static files.
01:56 PM Cloning 3 application files.
01:56 PM Uploading 1 files and blobs.
01:56 PM Uploaded 1 files and blobs
01:56 PM Compilation starting.
01:57 PM Compilation completed.
01:57 PM Starting deployment.
01:57 PM Checking if deployment succeeded.
01:57 PM Deployment successful.
01:57 PM Checking if updated app version is serving.
01:57 PM Completed update of app: cloud-chess, version: 2
01:57 PM Uploading index definitions.
2013-07-07 13:57:18 (Process exited with code 0)

棋盘.py

import os

import webapp2
import jinja2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    extensions=['jinja2.ext.autoescape'])

class MainHandler(webapp2.RequestHandler):
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('files/html/chess.html')
        self.response.write(template.render())

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

应用程序.yaml

application: cloud-chess
version: 2
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /html
  static_dir: files/html/

- url: /images
  static_dir: files/images/

- url: /scripts
  static_dir: files/scripts/

- url: .*
  script: chessboard.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest
4

2 回答 2

2

您的问题是您尝试加载的模板位于您的 static 指令html中。

无需将模板部署为静态资源 - 事实上您可能不应该这样做。

当您部署静态资源时,您的应用程序通常无法读取它们。最近app.yaml添加了一条指令以允许您阅读这些资源。

除非您希望静态提供 html 文件,否则只需删除/htmlstatic 指令,或将模板移动到其他地方。

或添加指令。 application_readable/html静态处理程序

请参阅静态处理程序的文档https://developers.google.com/appengine/docs/python/config/appconfig#Static_Directory_Handlers

就我个人而言,我建议不要静态提供 jinja 模板以及使用它们进行渲染。

为什么这在开发环境中工作 - 开发环境不使用不同的存储机制来提供静态和应用程序可读资源。

于 2013-07-09T03:15:13.573 回答
0

您不能将模板存储在静态目录中。

只需/html从 app.yaml 中删除处理程序,如下所示:

application: cloud-chess
version: 2
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /images
  static_dir: files/images/

- url: /scripts
  static_dir: files/scripts/

- url: .*
  script: chessboard.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest
于 2013-07-09T05:04:18.707 回答