以下是我的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
为什么我得到上述异常并且我该如何解决这个问题?请帮忙
答案 0 :(得分:0)
TemplateDoesNotExist: index.html
你有一个名为index.html
的文件吗?如果你不这样做,你所看到的正是会发生什么。