Can an app subclass a core django class to channge its behavior

34 views
Skip to first unread message

Mike Oliver

unread,
Aug 24, 2022, 9:53:01 AM8/24/22
to Django users
Hello, 

I want to follow a microservices architecture and have some shared services I can include in a process flow instead of the 1:1 View:Model 

Suggestions?

MO

Anh Nguyen

unread,
Aug 24, 2022, 10:23:41 PM8/24/22
to django...@googlegroups.com
Could you tell us more detail of process flow?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fea12690-f86e-4761-9aef-5be7358dea57n%40googlegroups.com.

Mike Oliver

unread,
Aug 25, 2022, 12:04:55 AM8/25/22
to Django users
Well I have continued to search and now I see that CustomMiddleware will do what I want, but I cannot find a current example and some of the StackOverflow answers are old and not working in the latest Django.

Mike Oliver

unread,
Aug 25, 2022, 12:09:34 AM8/25/22
to Django users
Currently, I have 
/mysite/
    mymiddleware.py
   settings.py

My CustomMiddlware class looks like...
class DoseControllerMiddleware(object):

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

my settings has...
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'mysite.mymiddleware.DoseControllerMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

runserver gives me...

ModuleNotFoundError: No module named 'mysite.mymiddleware'

Anh Nguyen

unread,
Aug 25, 2022, 2:00:33 AM8/25/22
to django...@googlegroups.com

Ur config with me are the same.

Screenshot_2022-08-25-12:50:38-1661406638.png
But i put it in the bottom of the middleware
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
    "chuthe.middlewares.supervisor.ChutheIOMiddleware",
]
Think you should try by shell to make sure you can call it, or importable `from mysite.mymiddleware import DoseControllerMiddleware`. Shell very helpful.

Mike Oliver

unread,
Aug 25, 2022, 2:48:15 AM8/25/22
to Django users
Ok will try the shell

Mike Oliver

unread,
Aug 25, 2022, 2:54:53 AM8/25/22
to Django users
>>> import mysite.mymiddleware.DoseControllerMiddleware
Traceback (most recent call last):
  File "<console>", line 1, in <module>

ModuleNotFoundError: No module named 'mysite.mymiddleware'
>>> import mymiddleware.DoseControllerMiddleware
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'mymiddleware'
>>>
hmmm

bboy...@gmail.com

unread,
Aug 25, 2022, 4:42:12 AM8/25/22
to Django users
It's seem you missed init file. that all.
Reply all
Reply to author
Forward
0 new messages