Cross-platform Django: isnโ€™t the middleware error

I am using the middleware provided at https://gist.github.com/426829 to do cross-site scripting.

However, when I add middleware to MIDDLEWARE_CLASSES , I get an error:

Incorrect Configured: not an intermediate module.

My MIDDLEWARE_CLASSES as follows:

 MIDDLEWARE_CLASSES = ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'TempMiddleware',) 

I have not changed the code in essence. process_request and process_response methods exist. I am running on Ubuntu the latest versions of Python and Django.

+4
source share
2 answers

What is TempMiddleware ? Module name or class name? As you can see with other entries, you need a fully Python-compliant path to the real class. If TempMiddleware is the name of the module, you need TempMiddleware.MyMiddlewareClass (and you really need to follow the PEP8 naming conventions) - and if it's a class name, you need my_module.TempMiddleware .

+3
source

Edit:

TempMiddleware not TempMiddleware . This is the name of the class, you must put the entire import path.

eg:

 'django.contrib.auth.middleware.AuthenticationMiddleware' 

but not

 'AuthenticationMiddleware' 

So, if your class is in app_name / middleware.py, it should be

 app_name.middlaware.TempMiddleware 

It just means that in your settings file, the MIDDLEWARE_CLASSES variable contains a list of modules in which one of the listed modules is not middleware.

Possible reasons:

  • You have added middleware that does not declare middleware methods: fix this by deleting the last middleware added.
  • you added the correct middleware, but forgot to put someone at the end of the name, so the lines are merged, and that does django, thinks that 2 middlewares are actually one: fix it by adding the missing to
+1
source

Source: https://habr.com/ru/post/1391223/


All Articles