2 things to possibly consider:

(1) Rather than including the '/' path separator character manually, the
os.path.join function is used to join path components using whichever
character is appropriate (e.g., '\' for Windows, '/' for Unix).
Try;

    path = os.path.join(os.path.dirname(__file__), "templates", "main.html")
    self.response.out.write(template.render(path, template_values))

(2) Ensure that the case of the actual filename matches that specified in
the code; main.HTML is not the same as main.html


On 12 October 2012 19:36, 唐元亮 <[email protected]> wrote:

> The following problem has bothered me for a long time. Can anybody help?
> Thanks
> The "main.html" file is in the "templates" directory under the app root
> directory.
> Google App Engine keeps complaining that it cannot find "main.html".
>
> app.yaml:
> ---------------------------
> application: templateTest
> version: 1
> runtime: python
> api_version: 1
>
> handlers:
> - url: /.*
>   script: main.py
> ---------------------------
>
> main.py:
> ---------------------------
> #!/usr/bin/env python2.7
> # -*- coding: utf-8 -*-
>
> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
> import os
> from google.appengine.ext.webapp import template
>
> class MainPage(webapp.RequestHandler):
>     def get(self):
>         path = os.path.join(os.path.dirname(__file__),
> "templates/main.html")
>         self.response.out.write(template.render(path, {}))
>
> application = webapp.WSGIApplication([("/", MainPage)], debug=True)
>
> def main():
>     run_wsgi_app(application)
>
> if __name__ == "__main__":
>     main()
> ---------------------------
>
>
> The error message:
>
> .../google_appengine/lib/django_1_2/django/template/loader.py", line 138, in 
> find_template
>     raise TemplateDoesNotExist(name)
> TemplateDoesNotExist: main.html
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/ncK-eBY0jKgJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to