Django/docs/3.0.x/ modules/django/contrib/sites/middleware
来自菜鸟教程
django.contrib.sites.middleware 源代码
from django.utils.deprecation import MiddlewareMixin
from .shortcuts import get_current_site
[文档]class CurrentSiteMiddleware(MiddlewareMixin):
"""
Middleware that sets `site` attribute to request object.
"""
def process_request(self, request):
request.site = get_current_site(request)