cardinal_pythonlib.django.middleware


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Django middleware classes.

class cardinal_pythonlib.django.middleware.DisableClientSideCachingMiddleware(get_response=None)[source]

Django middleware to ask the client never to cache headers for this page.

class cardinal_pythonlib.django.middleware.LoginRequiredMiddleware(get_response=None)[source]

Middleware that requires a user to be authenticated to view any page other than LOGIN_URL. Exemptions to this requirement can optionally be specified in settings via a list of regular expressions in LOGIN_EXEMPT_URLS (which you can copy from your urls.py).

Requires authentication middleware and template context processors to be loaded. You’ll get an error if they aren’t.

Other way of doing exemptions, for an exempt view:

def someview(request, *args, **kwargs):
    # body of view
someview.login_required = False

class SomeView(View):
    login_required = False
    # body of view
class cardinal_pythonlib.django.middleware.UserBasedExceptionMiddleware(get_response=None)[source]

Django middleware to report debugging information upon an exception, if the user is a superuser.