我有自定义中间件,当我将它添加到我的 settings.py 中的 MIDDLEWARE_CLASSES 元组时,网站上的所有 css 和图像都会消失,只留下文本。
中间件.py
from django.shortcuts import redirect
from django.core import urlresolvers
class AcceptTOSMiddleware(object):
def process_request(self, request):
login_url = urlresolvers.reverse('login')
tos_url = urlresolvers.reverse('tos')
if request.path not in [login_url, tos_url]:
profile = request.user.get_profile()
if not profile.tos:
return redirect(tos_url)
return None
设置.py
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'pagination.middleware.PaginationMiddleware',
'utils.middleware.AcceptTOSMiddleware'
)
有谁知道为什么会发生这种情况?