Try to create a sample test.py file, with content:
import os
print('first:')
print( __file__ )
print('second:')
print(os.path.dirname(__file__))
print('third:')
print(os.path.dirname('/some/dir/test.py'))

Run it, python test.py:
first:
test.py
second:
( ... blank ...)
third:
/some/dir

So you can see that the os.path.dirname is not being used properly. It 
should not be used on __file__ which returns only plain filename, not the 
fullpath.

Try to replace os.path.dirname with os.path.realpath

On Friday, October 12, 2012 4:36:09 PM UTC+8, 唐元亮 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/-/eVTWxKMYcDkJ.
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