Template not found error using Apache2 and webapp2 with jinja2

22 views
Skip to first unread message

Mike Cole

unread,
Jan 26, 2016, 2:48:17 PM1/26/16
to webapp2
I decided to jump ship and move my GAE app to a local server running Apache2.  I'm hitting a wall trying to configure it and continuing to get the following error when loading:

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 26, in get
    self.render_template('index.html', name=self.request.get('name'))
  File "/var/www/exmqa/main.py", line 22, 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)
TemplateNotFound: index.html

I'm not sure what to do with this, as there's no reason I can think of for it.  I've changed a lot of little things here and there trying to get it to work.  My main.py file works fine, unless I try to use a template.  Since I rather like templates, I want to use them.  I suspect I have something wrong in the apache config file, but I don't know what.  main.py lives in the root, and the templates directory is also there.  I added aliases to the apache config file to allow for /templates/, /css/, /js/ etc. to be accessible, and I can go to <URL>/templates/index.html in my browser, so I know that apache is able to get to that directory.  Yet still, jinja2 is failing to load the template.  

I have this configured in my main.py file:

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

I'm at a loss here.  I just want to be able to port a GAE app over to a local server, and it seems like it should be easier than this.  I'm sure I'm missing something stupid and simple, so please someone point out what I have failed to do correctly.  

Thanks!
Reply all
Reply to author
Forward
0 new messages