请对照 你自己的模块进行对照,请看我的目录结构,当时的目录如下,报错是这个:
django.core.exceptions.ImproperlyConfigured: WSGI application 'zqxt_views.wsgi.application' could not be loaded; Error importing module.
下面看正确配置:
1.目录结构
2.settings.py
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',
#判断浏览器
'zqxt_views.my_middleware.CheckSourceMiddleware',
]
3.中间件 my_middleware.py :
from django.utils import deprecation
class CheckSourceMiddleware(deprecation.MiddlewareMixin):
def process_request(self, request):
from_source = request.META['HTTP_USER_AGENT']
print('from_source', from_source)
if 'iPhone' in from_source:
request.session['from_source'] = 'iphone'
else:
request.session['from_source'] = 'pc'