CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=2eecdc5e8dea763d50bbca06; HttpOnly; Path=/; Secure
set-cookie: trac_session=04c27c62b93a9330d2c8b0eb; expires=Tue, 21 Oct 2025 13:12:42 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 13:12:42 GMT
x-served-by: cache-fra-etou8220058-FRA, cache-bom-vanm7210052-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753276362.214694,VS0,VE283
vary: Accept-Encoding
MultiHostMiddleware – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
# File: README """ A simple middleware component that lets you use a single Django instance to server multiple distinct hosts. IMPORTANT!! Make sure this is the FIRST entry in your MIDDLEWARE_CLASSES Revision log: v1.2 - 10th January 2012 (Cal Leeming - cal.leeming@simplicitymedialtd.co.uk) * Added 'LoadingTime' response header (tells us how long the request took to process) * Added 'MultiHost' response header (tells us if multihost was used or not) * Added 'HOST_MIDDLEWARE_URLCONF_MAP' example * Cleaned up code slightly """
# File: settings.py HOST_MIDDLEWARE_URLCONF_MAP = { # Control Panel "www.example.com": "webapp.sites.example.urls", }
# File: multihost.py import time from django.conf import settings from django.utils.cache import patch_vary_headers class MultiHostMiddleware: def process_request(self, request): try: request.META["LoadingStart"] = time.time() host = request.META["HTTP_HOST"] #if host[-3:] == ":80": # host = host[:-3] # ignore default port number, if present # best way to do this. host_port = host.split(':') if len(host_port)==2: host = host_port[0] if host in settings.HOST_MIDDLEWARE_URLCONF_MAP: request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host] request.META["MultiHost"] = str(request.urlconf) else: request.META["MultiHost"] = str(settings.ROOT_URLCONF) except KeyError: pass # use default urlconf (settings.ROOT_URLCONF) def process_response(self, request, response): if 'MultiHost' in request.META: response['MultiHost'] = request.META.get("MultiHost") if 'LoadingStart' in request.META: _loading_time = time.time() - int(request.META["LoadingStart"]) response['LoadingTime'] = "%.2fs" % ( _loading_time, ) if getattr(request, "urlconf", None): patch_vary_headers(response, ('Host',)) return response
Last modified
10 years ago
Last modified on Oct 12, 2015, 6:09:24 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.