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