Updated permission denied middleware to comform to coding style
This commit is contained in:
@@ -11,16 +11,16 @@ class PermissionDeniedMiddleware(object):
|
|||||||
if isinstance(exception, PermissionDenied):
|
if isinstance(exception, PermissionDenied):
|
||||||
try:
|
try:
|
||||||
# Handle import error but allow any type error from view
|
# Handle import error but allow any type error from view
|
||||||
callback = getattr(import_module(settings.ROOT_URLCONF), 'handler403')
|
callback = getattr(import_module(settings.ROOT_URLCONF), u'handler403')
|
||||||
return callback(request, exception)
|
return callback(request, exception)
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
# Try to get a 403 template
|
# Try to get a 403 template
|
||||||
try:
|
try:
|
||||||
# First look for a user-defined template named "403.html"
|
# First look for a user-defined template named "403.html"
|
||||||
t = loader.get_template('403.html')
|
t = loader.get_template(u'403.html')
|
||||||
except TemplateDoesNotExist:
|
except TemplateDoesNotExist:
|
||||||
# If a template doesn't exist in the projct, use the following hardcoded template
|
# If a template doesn't exist in the projct, use the following hardcoded template
|
||||||
t = Template("""{% load i18n %}
|
t = Template(u'''{% load i18n %}
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||||
"http://www.w3.org/TR/html4/strict.dtd">
|
"http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
@@ -31,7 +31,7 @@ class PermissionDeniedMiddleware(object):
|
|||||||
<h1>{% trans "Access Denied (403)" %}</h1>
|
<h1>{% trans "Access Denied (403)" %}</h1>
|
||||||
{% trans "We're sorry, but you are not authorized to view this page." %}
|
{% trans "We're sorry, but you are not authorized to view this page." %}
|
||||||
</body>
|
</body>
|
||||||
</html>""")
|
</html>''')
|
||||||
|
|
||||||
# Now use context and render template
|
# Now use context and render template
|
||||||
c = RequestContext(request)
|
c = RequestContext(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user