How to use a template html in different folder on Google App Engine python?
Question: I am trying to use a templated html file in a different folder on python and I
am running into file not found error. For example,

    
    
    index_path = os.path.join (os.path.join(os.path.dirname( __file__ ), '..', 'html'), 'index.html')
    

index.html is in html folder. My python handler code is in handlers folder.

    
    
    .
    ├── app.yaml
    ├── handlers
    ├── html
    

How does the project structure look like when it is deployed in Google App
Engine?

_Note_ : I am using:

    
    
    from google.appengine.ext.webapp import template
    template.render(index_path, {})
    

I modified the code based on suggestions below, still no luck:

**handlers/index.py:**

    
    
    jinja_environment = jinja2.Environment(
        loader=jinja2.FileSystemLoader(os.path.dirname('html')))
    
    index_file = 'index.html'
    template = jinja_environment.get_template(index_file)
    content = template.render({})
    
    self.response.out.write(content)
    

**html/index.html:**

**From app.yaml:**

    
    
    libraries:
    - name: jinja2
      version: latest
    


Answer: The preferred way of rendering templates in GAE is to use Jinja2. Jinja2 makes
use of [loaders](http://jinja.pocoo.org/docs/dev/api/#loaders).

> Loaders are responsible for loading templates from a resource such as the
> file system

You'll want to modify `app.yaml` so your application has access to Jinja2.

    
    
    libraries:
    - name: jinja2
      version: latest
    

then prep a template environment and a loader to help get templates from your
`html` folder

    
    
    import jinja2
    
    env = jinja2.Environment(loader=jinja2.FileSystemLoader('html'))
    
    template = env.get_template('index.html')
    ...
    template.render(template_values)
    

* * *

EDIT :

Make the handlers folder a package by adding a `__init__.py`. With a dir
structure such as:

    
    
    .
    ├── app.yaml
    ├── handlers
    │   ├── hello.py
    │   └── __init__.py
    └── html
        └── index.html 
    

Then in the `handlers` section of `app.yaml` something akin to the following
should do:

    
    
    handlers:
    - url: /.*
      script: handlers.hello.app # with app defined in hello.py
    ...
    libraries:
    - name: jinja2
      version: latest
    

