OdraEncoded

Webapp2 jinja2 error template handler

Dec 11th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def HTTPErrorHandler(request, response, exception):
  2.     if isinstance(exception, webapp2.HTTPException):
  3.         code = exception.code
  4.     else: code = 500
  5.    
  6.     while(True):
  7.         try:
  8.             template = jinja_env.get_template(str(code) + ".html")
  9.             response.write(template.render())
  10.             response.set_status(code)
  11.             break
  12.         except:
  13.             if code == 500:
  14.                 response.write("<h1>Error 500</h1>The server is absolutely broken right now")
  15.                 response.set_status(500)
  16.                 break
  17.             else:
  18.                 code = 500
Advertisement
Add Comment
Please, Sign In to add comment