diff --git a/docs/advanced_topics/add_to_django_project.rst b/docs/advanced_topics/add_to_django_project.rst index 53d06edb39..1d5cf02e55 100644 --- a/docs/advanced_topics/add_to_django_project.rst +++ b/docs/advanced_topics/add_to_django_project.rst @@ -40,7 +40,7 @@ Middleware (``settings.py``) 'wagtail.contrib.redirects.middleware.RedirectMiddleware', ] -Wagtail requires several common Django middleware modules to work and cover basic security. Wagtail provides its own middleware to cover these tasks: +Wagtail depends on the default set of Django middleware modules, to cover basic security and functionality such as login sessions. One additional middleware module is provided: ``RedirectMiddleware`` Wagtail provides a simple interface for adding arbitrary redirects to your site and this module makes it happen. diff --git a/wagtail/core/middleware.py b/wagtail/core/middleware.py index 923f47b947..74888ba222 100644 --- a/wagtail/core/middleware.py +++ b/wagtail/core/middleware.py @@ -5,18 +5,20 @@ from wagtail.core.models import Site from wagtail.utils.deprecation import RemovedInWagtail211Warning +warnings.warn( + 'wagtail.core.middleware.SiteMiddleware and the use of request.site is deprecated. ' + 'Please update your code to use Site.get_for_request(request) in place of request.site, ' + 'and remove wagtail.core.middleware.SiteMiddleware from MIDDLEWARES', + RemovedInWagtail211Warning +) + + class SiteMiddleware(MiddlewareMixin): def process_request(self, request): """ Set request.site to contain the Site object responsible for handling this request, according to hostname matching rules """ - warnings.warn( - 'Wagtail SiteMiddleware and the use of request.site is deprecated ' - 'and will be removed in Wagtail 2.11. Update your middleware settings.', - RemovedInWagtail211Warning, stacklevel=2 - ) - try: request.site = Site.find_for_request(request) except Site.DoesNotExist: