First Version
[django403.git] / views.py
blob41315c2fa58c042171bfa9e5a8332ac5b899252f
1 # vim:ts=2:sw=2:et
3 # Django Default 403.html handler
4 # http://wtanaka.com/django/django403
6 # Copyright (C) 2009 Wesley Tanaka <http://wtanaka.com/>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import django.http
22 import django.template
23 import django.template.loader
25 def fallback_403(request):
26 """
27 Fallback 403 handler which prints out a hard-coded string patterned
28 after the Apache default 403 page.
30 Templates: None
31 Context: None
32 """
33 return django.http.HttpResponseForbidden(
34 _("""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
35 <html><head>
36 <title>403 Forbidden</title>
37 </head><body>
38 <h1>Forbidden</h1>
39 <p>You don't have permission to access %(path)s on this server.</p>
40 <hr>
41 </body></html>""") % {'path': request.path})
43 def access_denied(request, template_name='403.html'):
44 """
45 Default 403 handler, which looks for the which prints out a hard-coded string patterned
46 after the Apache default 403 page.
48 Templates: `403.html`
49 Context:
50 request
51 The django request object
52 """
53 t = django.template.loader.get_template(template_name)
54 template_values = {}
55 template_values['request'] = request
56 return django.http.HttpResponseForbidden(
57 t.render(django.template.RequestContext(request, template_values)))