Template not found error when using jinja2 and webapp2 on Apache2 with mod_wsgi
<p>I'm banging my head against a wall right now.  I've been fighting with this for hours, and I'm just done for the day.  I'm hoping someone out there can clue me in.  </p>

<p>I'm receiving this error from my server after configuring apache with mod_wsgi to try and run a webapp2 with jinja2 Python application locally (not using the gae developer server) so I can move away from gae for some local projects I have in mind and not have to learn a new framework at the moment.  </p>

<pre><code>Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/usr/local/lib/python2.7/dist-packages/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/var/www/exmqa/main.py", line 39, in get
self.render_template('index.html', name=self.request.get('name'))
File "/var/www/exmqa/main.py", line 35, in render_template
self.response.write(self.jinja2.render_template(filename, **template_args))
File "/usr/local/lib/python2.7/dist-packages/webapp2_extras/jinja2.py", line 158, in render_template
return self.environment.get_template(_filename).render(**context)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 774, in _load_template
cache_key = self.loader.get_source(self, name)[1]
File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 187, in get_source
raise TemplateNotFound(template)
</code></pre>

<p>TemplateNotFound: index.html</p>

<p>I have no idea why.  The app was working fine on gae, and I followed instructions I could find online to move it over, including installing webapp2, jinja2, patch, and webob.  I have tried about 2 dozen different suggestions or ideas that sprang from reading on SO and other sites, and have still not figured out why I am continuing to see this.  </p>

<p>For reference, here's my current main.py:</p>

<pre><code>#!/usr/bin/env python

import webapp2
from webapp2_extras import jinja2
from jinja2 import Environment, FileSystemLoader
import os
import sys
sys.path.insert(0, '/var/www/exmqa/modules')
import dmpautomation

template_dir = '/templates'
loader = FileSystemLoader(template_dir)
environment = Environment(loader=loader)

class BaseHandler(webapp2.RequestHandler):
    @webapp2.cached_property
    def jinja2(self):
        return jinja2.get_jinja2(app=self.app)

    def render_template(self, filename, **template_args):
        self.response.write(self.jinja2.render_template(filename, **template_args))

class Home(BaseHandler):
    def get(self):
        self.render_template('index.html',     name=self.request.get('name'))

class Automation(BaseHandler):
    def get(self):
        self.render_template('dmpauto.html', name=self.request.get('name'))
    def post(self):
        IP = self.request.get("ipaddress")
        self.response.write(IP)
        callable(dmpautomation.autotest(IP))

class Soak(BaseHandler):
    def get(self):
        self.render_template('dmpsoak.html', name=self.request.get('name'))







app = webapp2.WSGIApplication([
    ('/', Home),
    ('/dmpauto', Automation),
    ('/dmpsoak', Soak)
], debug=True)
</code></pre>

<p>Anyone have any suggestions of what I need to do differently to get jinja2 templating working in an Apache2 with mod_wsgi environment running Python and webapp2?  Is there some config for Apache that I'm not aware of and have been missing?  Something, anything, this is getting ridiculous.</p>

<p>Thanks in advance for anything you might be able to suggest.  </p>

<p>EDITED: Adding the contents of my exmqa.conf file (Apache config file) for whatever information that may provide.  The two <code>&lt;Directory&gt;</code> sections were added from information I found here and there trying to debug this. From everything I've been able to find thus far, the Alias lines I added should be all that's needed.  I'm wondering if there's a permissioning issue somewhere that allows me to access the files directly, but not the running instance of Apache.  I'd find that weird, since apache2 is running as root and www-data, and I would think that would give it access to the world.  Obviously, Apache is not my expertise.  </p>

<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGICallableObject app

&lt;VirtualHost *:9000&gt;
    ServerName exmqa
    ServerAlias exmqa.corp.uievolution.com

    ServerAdmin mcole@uievolution.com
    DocumentRoot /var/www/exmqa
    WSGIScriptAlias / /var/www/exmqa/modules/main.py

    &lt;Directory /var/www/exmqa&gt;
    Require all granted
    &lt;/Directory&gt;

    &lt;Directory /var/www/exmqa/templates&gt;
    Require all granted
    &lt;/Directory&gt;

    Alias /css/ /var/www/exmqa/css/
    Alias /images/ /var/www/exmqa/images/
    Alias /js/ /var/www/exmqa/js/
    Alias /scripts/ /var/www/exmqa/scripts/
    Alias /templates/ /var/www/exmqa/templates/

    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

&lt;/VirtualHost&gt;
</code></pre>