Instead of printing out Watchdog, you can "print request.path" to see
which two requests are triggering the middleware.
When you know which additional request is causing the problem, you can
use a decorator to filter it. Here is what I do:
---------------------------------------
In middleware.py:
Class MyMiddleWare:
@forNonStaticRequest
def process_request(self, request):
# Your code goes here
pass
---------------------------------------
And, somewhere else in your project:
===========================================================================
from functools import wraps
from YOURPROJECTNAME.settings import DEBUG
def __forNonStaticRequest(func):
@wraps(func)
def wrapper(SELF, request):
prefix = ('/js/', '/images/', '/upload/', '/style/', '/
__debug__/')
if request.path.startswith(prefix):
return None
return func(SELF, request)
return wrapper
forNonStaticRequest = __forNonStaticRequest if DEBUG else (lambda u:
u)
===========================================================================
What these codes do is to prevent static files request from triggering
the middleware *only* when you're running development server.
You need to properly handle static files when you actually deploy them
in production environment.
I think this will help you.