I have written custom middleware which checks invites from users. The idea is to restrict the access to the website for users without invites. Everything is woking fine, except that users can see parts of the site when 404 or any other exception occurs and I don't want it.
I am using Django 1.9. In previous versions (as I remember) there was Exception middleware, but now I don't see it. I tried to put my middleware on the top of the stack but it doesn't help. What else can I do?
Lets say, I have following middleware:
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'myproject.middleware.InviteLoginForWebsiteMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
]
Here are my urls which redirect to handlers:
urlpatterns = [
url(r'^403/$', views.handler403, name="403"),
url(r'^404/$', views.handler404, name="404"),
url(r'^500/$', views.handler500, name="500"),
]
Thanks!
I have solved the question by using process_request() rather then process_view() in my custom middleware. Thanks to all!