From 69c258f9adf78755164f77487082be95a5f24b63 Mon Sep 17 00:00:00 2001 From: Igor Date: Fri, 25 Jan 2019 01:21:49 +0300 Subject: [PATCH] Fix DjangoMiddleware for django >= 1.10 --- README.md | 6 +++--- chromelogger.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e68f3da..393077b 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,9 @@ Since every framework deals with setting headers slightly differently the librar The library includes a middleware for using with Django. All you have to do is in your ``settings.py`` file make sure to update your list of middleware and add ```python -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10 'chromelogger.DjangoMiddleware' -) +] ``` After that you can import the chromelogger class from any file in your application and add logs. @@ -74,7 +74,7 @@ For using chromelogger with Flask, you can use a custom response-handler like th if app.debug: import chromelogger as console - + @app.after_request def chromelogger(response): header = console.get_header() diff --git a/chromelogger.py b/chromelogger.py index f7bc2f7..7399574 100644 --- a/chromelogger.py +++ b/chromelogger.py @@ -152,6 +152,12 @@ def table(*args): _log(args) +try: + from django.utils.deprecation import MiddlewareMixin +except ImportError: + MiddlewareMixin = object + + # this is middleware for django. ater this module is installed just add # "chromelogger.DjangoMiddleware" to your MIDDLEWARE_CLASSES in settings.py # @@ -160,7 +166,7 @@ def table(*args): # chromelogger.log('Hello world!') # # from anywhere in your Django application -class DjangoMiddleware(object): +class DjangoMiddleware(MiddlewareMixin): def process_response(self, request, response): header = get_header() if header is not None: