-
Notifications
You must be signed in to change notification settings - Fork 2k
/
template.py
38 lines (30 loc) · 1.17 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import ckan.lib.base as base
import ckan.lib.render
class TemplateController(base.BaseController):
def view(self, url):
"""By default, the final controller tried to fulfill the request
when no other routes match. It may be used to display a template
when all else fails, e.g.::
def view(self, url):
return render('/%s' % url)
Or if you're using Mako and want to explicitly send a 404 (Not
Found) response code when the requested template doesn't exist::
import mako.exceptions
def view(self, url):
try:
return render('/%s' % url)
except mako.exceptions.TopLevelLookupException:
abort(404)
By default this controller aborts the request with a 404 (Not
Found)
"""
try:
return base.render(url)
except ckan.lib.render.TemplateNotFound:
if url.endswith('.html'):
base.abort(404)
url += '.html'
try:
return base.render(url)
except ckan.lib.render.TemplateNotFound:
base.abort(404)