Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

An extension for django.contrib.sites, featuring domain redirects and automatic population of the django.contrib.sites.Site table based on settings.

Project Description

Extensions to django.contrib.sites.


  • Domain redirects: handles smart redirecting to a main domain from alias domains. Taking http/https into consideration.
  • Site auto-population: automatically populates the Domain name in django.contrib.sites.Site.domain based on the ALDRYN_SITES_DOMAINS setting.


  • add aldryn_sites to INSTALLED_APPS.
  • add aldryn_sites.middleware.SiteMiddleware to MIDDLEWARE_CLASSES (place it before djangosecure.middleware.SecurityMiddleware if redirects should be smart about alias domains possibly not having a valid certificate of their own. The middleware will pick up on SECURE_SSL_REDIRECT from django-secure.)


    1: {  # matches SITE_ID
        'domain': '',  # main domain that all domains in redirects will redirect to.
                                      # Auto populates ``django.contrib.sites.Site.domain``
        'aliases': [                  # these domains will be accessible like the main domain (no redirect).
            r'^[a-z0-9-]+\.anysub\.com$',  # regexes are supported
        'redirects': [                # these domains will be redirected to the main domain.
            '',            # add ``'*'`` to redirect all non-main domains to the main one.
            r'^[a-z0-9-]+\.my-redirect-domain\.com$',  # regexes are supported
            r'.*',  # matches any domain (Makes the above rules useless. It's just an example)

When using regexes:

  • exact matches win over pattern matches
  • pattern redirect matches win over pattern alias matches

Further Settings

set ALDRYN_SITES_SET_DOMAIN_NAME to False if you don’t want django.contrib.sites.Site.domain to be auto-populated (default: True).


  • validate settings
  • test settings validators
  • log warning if there are Sites in the database that are not in the settings
  • pretty display of how redirects will work (in admin and as a simple util)
  • regex support for aliases
  • form to test redirect logic
  • pre-compile and cache regexes

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aldryn_sites-0.5.8-py2-none-any.whl (10.5 kB) Copy SHA256 hash SHA256 Wheel 2.7 May 16, 2017
aldryn-sites-0.5.8.tar.gz (6.5 kB) Copy SHA256 hash SHA256 Source None May 16, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page