0
votes

I have a very basic jinja template, which works OK in displaying htm, but the log complains about favicon.ico even though I have it in both / and /templates. what did I do wrong? also, am I getting an error in my css load?

import jinja2
import os
import logging
import webapp2

JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'])

class MainHandler(webapp2.RequestHandler):

def get(self):
    path = self.request.path
    logging.info('from main %s', path)
    if (path=='/'):
      templa=JINJA_ENVIRONMENT.get_template('/templates/index.htm')
    else:
      templa=JINJA_ENVIRONMENT.get_template(path)
    try:
      self.response.write(templa.render({})) 

    except:
      self.response.out.write('Error - unable to find %s' % path)

app = webapp2.WSGIApplication([('/.*',MainHandler)],
 debug=True)

------ showing only error INFO 2013-10-07 19:44:53,500 index4.py:44] from main /templates/topics.htm INFO 2013-10-07 19:44:53,516 dev_appserver.py:3103] "GET /templates/topics.htm HTTP/1.1" 200 - INFO 2013-10-07 19:44:53,532 dev_appserver.py:3103] "GET /static/glike.css HTTP/1.1" 304 - INFO 2013-10-07 19:44:53,609 index4.py:44] from main /favicon.ico ERROR 2013-10-07 19:44:53,609 webapp2.py:1552] 'utf8' codec can't decode byte 0x96 in position 142: invalid start byte Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1535, in call rv = self.handle_exception(request, response, e) File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1529, in call rv = self.router.dispatch(request, response) File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response) File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in call return handler.dispatch() File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug) File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch return method(*args, **kwargs) File "C:\projects\apps\ae-07-grades\index4.py", line 48, in get templa=JINJA_ENVIRONMENT.get_template(path) File "C:\Program Files\Google\google_appengine\lib\jinja2\jinja2\environment.py", line 719, in get_template return self._load_template(name, self.make_globals(globals)) File "C:\Program Files\Google\google_appengine\lib\jinja2\jinja2\environment.py", line 693, in _load_template template = self.loader.load(self, name, globals) File "C:\Program Files\Google\google_appengine\lib\jinja2\jinja2\loaders.py", line 115, in load source, filename, uptodate = self.get_source(environment, name) File "C:\Program Files\Google\google_appengine\lib\jinja2\jinja2\loaders.py", line 169, in get_source contents = f.read().decode(self.encoding) File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0x96 in position 142: invalid start byte INFO 2013-10-07 19:44:53,641 dev_appserver.py:3103] "GET /favicon.ico HTTP/1.1" 500 -

1

1 Answers

2
votes

It looks like jinja2 is trying to load /favicon.ico as a jinja template, and is choking on it.

The usual way to handle /favicon.ico is to declare it as a static file in app.yaml.

See favicon.ico "not found error" in app engine