Type Error in get_wsgi_application() in Django 2.x

2019-04-16 08:13发布

I am migrating a web application from Django 1.9 to 2.0.2. The code is

import os
import sys

path = '/mypath'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Myapplication.settings")


from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

However, if I try to execute this, I get an error:

File "/home/.../wsgi.py", line 29, in <module>
application = get_wsgi_application()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/home/.../lagerthree/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 140, in __init__
self.load_middleware()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/handlers/base.py", line 39, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters

According to StackExchange and other sites, the cause of this error is the deprecation of certain things from 1.x to 2.x and the solution is the MiddlewareMixin which should be used like this: class FOOMiddleware(MiddlewareMixin): ...

My MIDDLEWARE settings are:

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'reversion.middleware.RevisionMiddleware',
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'users.middleware.TimezoneMiddleware')

But I don't have any classes and also, the get_wsgi_application() function should still work, as far as I know.
How should I solve this?

0条回答
登录 后发表回答