template.py 966B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. """Fallback controller."""
  3. from pod.lib.base import BaseController
  4. from tg import abort
  5. __all__ = ['TemplateController']
  6. class TemplateController(BaseController):
  7. """
  8. The fallback controller for pod.
  9. By default, the final controller tried to fulfill the request
  10. when no other routes match. It may be used to display a template
  11. when all else fails, e.g.::
  12. def view(self, url):
  13. return render('/%s' % url)
  14. Or if you're using Mako and want to explicitly send a 404 (Not
  15. Found) response code when the requested template doesn't exist::
  16. import mako.exceptions
  17. def view(self, url):
  18. try:
  19. return render('/%s' % url)
  20. except mako.exceptions.TopLevelLookupException:
  21. abort(404)
  22. """
  23. def view(self, url):
  24. """Abort the request with a 404 HTTP status code."""
  25. abort(404)