0

以下是我的 app.yaml 和 main.py 文件,我正在尝试使用谷歌应用引擎运行一个小项目,但我失败了

application: app
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
  static_files: \1
  upload: (.*\.(gif|png|jpg|ico|js|css))

- url: /robots.txt
  static_files: robots.txt
  upload: robots.txt 

- url: .*
  script: main.py

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

Index.html 未显示,并且我在日志中出现以下异常:

ERROR    2013-03-27 11:14:42,078 webapp2.py:1528] index.html
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "C:\Documents and Settings\Administrator\Desktop\MSLS\app\main.py", line 16, in get
    self.response.out.write (template.render (path, {}))
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 89, in render
    t = _load_internal_django(template_path, debug)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 163, in _load_internal_django
    template = django.template.loader.get_template(file_name)
  File "C:\Program Files\Google\google_appengine\google\appengine\_internal\django\template\loader.py", line 157, in get_template
    template, origin = find_template(template_name)
  File "C:\Program Files\Google\google_appengine\google\appengine\_internal\django\template\loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: index.html
ERROR    2013-03-27 11:14:42,483 cgi.py:121] Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\Desktop\MSLS\app\main.py", line 23, in <module>
    main ()
  File "C:\Documents and Settings\Administrator\Desktop\MSLS\app\main.py", line 20, in main
    util.run_wsgi_app (application)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 98, in run_wsgi_app
    run_bare_wsgi_app(add_wsgi_middleware(application))
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 116, in run_bare_wsgi_app
    result = application(env, _start_response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher

为什么我会收到上述异常,我该如何解决?请帮忙

4

1 回答 1

0

TemplateDoesNotExist: index.html

你有一个名为 的文件index.html吗?你所看到的正是如果你不这样做会发生什么。

于 2013-03-26T18:00:19.087 回答