【发布时间】:2019-10-07 22:58:32
【问题描述】:
我想在我的项目中创建自定义中间件。但我收到这样的错误:
[ django.core.exceptions.ImproperlyConfigured: WSGI application 'custommiddle.wsgi.application' could not be loaded; Error importing module. ]
我认为问题可能出在我的 python 版本上,我使用的是 3.7 版本。
这是我的文件夹结构:
custommiddle/ # project name
__init__.py
settings.py
urls.py
wsgi.py
cmiddle/ # app name
middle/ # directory
__init__.py
middleware.py
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
middleware.py
from django.conf import settings
class StackOverflowMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
return response
def process_exception(self, request, exception):
if settings.DEBUG:
print (exception.__class__.__name__)
print (exception.message)
return None
settings.py
INSTALLED_APPS = [ 'soet' ]
MIDDLEWARE_CLASSES = [ 'soet.middleware.StackOverFlowMiddleware' ]
【问题讨论】:
标签: python django python-3.x python-2.7 django-middleware