[Django] #32605: Custom Middleware Error ====> WSGI application '<ProjectName>.wsgi.application' could not be loaded; Error importing module.

38 views
Skip to first unread message

Django

unread,
Mar 30, 2021, 4:07:47 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Core | Version: 3.1
(System checks) | Keywords: Middleware, WSGI-
Severity: Normal | Error, Windows, Django3.1
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Greetings

Django: 3.1.7
OS: Windows 10 - 64 bit
Python: 3.8.6 - 64 bit

Project Name: coffehouse
App Names: about, stores, coffe_app

I was creating a custom middleware for my django project. And after adding
the path of middleware file to settings.py file (in MIDDLEWARE variable),
I got error below:

{{{
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application
'coffehouse.wsgi.application' could not be loaded; Error importing module.
}}}


#### settings.py:

{{{
INSTALLED_APPS = [
'coffe_app.apps.CoffeAppConfig',
'stores',
'about',

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',

'coffehouse.utils.middleware.CoffehouseMiddleware', <===
]

}}}

#### coffehouse\coffehouse\utils\middleware\CoffehouseMiddleware.py:

{{{
class CoffehouseMiddleware (object):
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response (request)
return response

def process_view (self, request, view_func, view_args, view_kwargs):
pass

def process_exception (self, request, exception):
pass

def process_template_response (self, request, response):
pass
}}}


#### wsgi.py:

{{{
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coffehouse.settings')
application = get_wsgi_application()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32605>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 30, 2021, 4:08:08 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (System | Version: 3.1
checks) |
Severity: Normal | Resolution:
Keywords: Middleware, WSGI- | Triage Stage:
Error, Windows, Django3.1 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alimp5):

* Attachment "errors for debugging.txt" added.

Django

unread,
Mar 30, 2021, 4:12:03 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: Uncategorized | Status: closed

Component: Core (System | Version: 3.1
checks) |
Severity: Normal | Resolution: invalid

Keywords: Middleware, WSGI- | Triage Stage:
Error, Windows, Django3.1 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Please don't use Trac as a support channel. Closing per
TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/32605#comment:1>

Django

unread,
Mar 30, 2021, 4:12:16 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: Uncategorized | Status: closed
Component: Core (System | Version: 3.1
checks) |
Severity: Normal | Resolution: invalid
Keywords: Middleware, WSGI- | Triage Stage:
Error, Windows, Django3.1 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by alimp5):

# FROM:
{{{


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',

'coffehouse.utils.middleware.CoffehouseMiddleware', <===
]

}}}


#### TO:
{{{


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',

'coffehouse.utils.middleware.CoffehouseMiddleware.CoffehouseMiddleware',
<===
]

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32605#comment:2>

Django

unread,
Mar 30, 2021, 4:12:29 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: Uncategorized | Status: closed
Component: Core (System | Version: 3.1
checks) |
Severity: Normal | Resolution: fixed

Keywords: Middleware, WSGI- | Triage Stage:
Error, Windows, Django3.1 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alimp5):

* resolution: invalid => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/32605#comment:3>

Django

unread,
Mar 30, 2021, 4:49:21 AM3/30/21
to django-...@googlegroups.com
#32605: Custom Middleware Error ====> WSGI application
'<ProjectName>.wsgi.application' could not be loaded; Error importing
module.
-------------------------------------+-------------------------------------
Reporter: alimp5 | Owner: nobody
Type: Uncategorized | Status: closed
Component: Core (System | Version: 3.1
checks) |
Severity: Normal | Resolution: invalid

Keywords: Middleware, WSGI- | Triage Stage:
Error, Windows, Django3.1 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* resolution: fixed => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/32605#comment:4>

Reply all
Reply to author
Forward
0 new messages