Skip to main content

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

Project description

https://travis-ci.org/aldryn/aldryn-sites.svg?branch=develop https://img.shields.io/coveralls/aldryn/aldryn-sites.svg

Extensions to django.contrib.sites.

Features

  • 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.

Installation

  • 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.)

configure ALDRYN_SITES_DOMAINS:

ALDRYN_SITES_DOMAINS = {
    1: {  # matches SITE_ID
        'domain': 'www.example.com',  # 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).
            'an.other.domain.com',
            r'^[a-z0-9-]+\.anysub\.com$',  # regexes are supported
        ],
        'redirects': [                # these domains will be redirected to the main domain.
            'example.com',            # add ``'*'`` to redirect all non-main domains to the main one.
            'example.ch',
            'www.example.ch',
            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).

TODOS

  • 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

Project details


Download files

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

Source Distribution

aldryn-sites-0.5.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

aldryn_sites-0.5.4-py2-none-any.whl (10.9 kB view details)

Uploaded Python 2

File details

Details for the file aldryn-sites-0.5.4.tar.gz.

File metadata

File hashes

Hashes for aldryn-sites-0.5.4.tar.gz
Algorithm Hash digest
SHA256 8d6a8f25e3f073870e8bc925d9e807ec2c3c1307f57a3b03e5e17dbcca680a38
MD5 99bacd884130f1dac7faed34c9c63843
BLAKE2b-256 a89da4308a2bcdccd9965b80458e586a806ecaec718cd4b4fd0c90b5511a83b8

See more details on using hashes here.

File details

Details for the file aldryn_sites-0.5.4-py2-none-any.whl.

File metadata

File hashes

Hashes for aldryn_sites-0.5.4-py2-none-any.whl
Algorithm Hash digest
SHA256 b1d35b95721ac273945ff6a2f8a03d8fb5d2691f130e99749c8e63ba0b9b4826
MD5 53b96c8e9e956bab3ea0152855d36d85
BLAKE2b-256 b2a138ea2bf2d6023d970df9348c28420c03ce2362eb472e51581812e837933c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page