Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32605 closed Uncategorized (invalid)

Custom Middleware Error ====> WSGI application '<ProjectName>.wsgi.application' could not be loaded; Error importing module.

Reported by: alimp5 Owned by: nobody
Component: Core (System checks) Version: 3.1
Severity: Normal Keywords: Middleware, WSGI-Error, Windows, Django3.1
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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()

Attachments (1)

errors for debugging.txt (4.1 KB ) - added by alimp5 4 years ago.

Download all attachments as: .zip

Change History (3)

by alimp5, 4 years ago

Attachment: errors for debugging.txt added

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

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

comment:2 by alimp5, 4 years ago

# 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',    <===
]

Note: See TracTickets for help on using tickets.
Back to Top