Creating CustomMiddleware

I created a custom mysite/ file as follows…

class DoseControllerMiddleware(object):

def process_request(self, request):
    get ready to call the Dose Controller
    print("DoseControllerModdleware.process_request Hooray")
    return None

This is in a file called mymiddleware located adjacent to

My settings looks like this…


When I runserver I get…

ModuleNotFoundError: No module named ‘mysite.mymiddleware’

I have tried it with a middleware folder with init with the in that folder and changed the path in MIDDLEWARE settings to match but ModuleNotFoundError.

This might be a typo in your post rather than the filename, but are you sure “mysite/” is correct? It must be the same as the full module path listed in the MIDDLEWARE setting, except with dot-notation instead of filepath-notation.

Other than that, is this the full code for the middleware class? The documentation on middleware specifies different hooks than process_request for processing requests. However, this shouldn’t have anything to do with the module not being found.