Django Code Snippets

Powered by PythonAnywhere and Django 1.8.6

HTTP Message - Exception

Date Added: Nov. 19, 2015, 4:05 p.m.

Author: django-snippets



from django.http import HttpResponseRedirect

class HttpMessageMiddleware(object):
    def process_exception(self, request, exception):
        if request.user.is_authenticated():
            request.user.message_set.create(message=unicode(exception))
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))


class HttpMessage(Exception):
    pass



 

Tags: django, python

Return to List