-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmiddleware.py
More file actions
19 lines (17 loc) · 767 Bytes
/
middleware.py
File metadata and controls
19 lines (17 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import traceback
from django.http import HttpResponseServerError
from django.template.loader import render_to_string
from django.shortcuts import render_to_response
class StaffOnlyMiddleware(object):
def process_request(self, request):
if not request.path.startswith('/admin'):
if not request.user.is_staff:
return render_to_response('404.html')
class ErrorHandlingMiddleware(object):
def process_exception(self, request, exception):
if request.is_ajax():
return HttpResponseServerError(traceback.format_exc(),
content_type='text/plain')
# else:
# return HttpResponseServerError(render_to_string('500.html',
# dict(message=traceback.format_exc())))