Dynamic ALLOWED_HOSTS based on the configured django.contrib.sites
Project description
============================= django-dynamic-allowedsites
Django 1.6+ library for setting your ALLOWED_HOSTS
based on the domains in django.contrib.sites
.. image:: https://travis-ci.org/frankyjquintero/django-allowedsites.svg?branch=master :target: https://travis-ci.org/frankyjquintero/django-allowedsites
Usage is something like the following, in your settings.py
or equivalent::
from allowedsites import AllowedSites
ALLOWED_HOSTS = AllowedSites(defaults=('mytestsite.com',))
Or, if you want to use your cache backend::
from allowedsites import CachedAllowedSites
ALLOWED_HOSTS = CachedAllowedSites()
A single key, allowedsites
will be inserted containing an unsorted collection
of all the domains that are in the django.contrib.sites
. For the sake of allowing
multiple processes to keep up to date with the Site
values without hitting
the database, using a shared cache (ie: not LocMemCache
) is encouraged.
The CachedAllowedSites
also provides an update_cache
class method which
may be used as a signal listener::
from django.db.models.signals import post_save
from django.contrib.sites.models import Site
post_save.connect(CachedAllowedSites.update_cache, sender=Site,
dispatch_uid='update_allowedsites')
You can modify the the defaults::
from allowedsites import AllowedSites
ALLOWED_HOSTS = AllowedSites(defaults=('mytestsite.com',))
ALLOWED_HOSTS += AllowedSites(defaults=('anothersite.net',))
ALLOWED_HOSTS -= AllowedSites(defaults=('mytestsite.com',))
# ultimately, only anothersite.net is in the defaults
Other uses?
It may work with django-csp
_ (Content Security Policy headers),
django-cors-headers
_ Cross-Origin Resource Sharing (CORS) headers and others. I don't know.
.. _django-csp: https://github.com/mozilla/django-csp .. _django-cors-headers: https://github.com/adamchainz/django-cors-headers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-dynamic-allowedsites-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 147dd7d4c2b11ff1949ca345d942278699f91489a246cb9d0891a2a139f2bf8c |
|
MD5 | 704f55a75bd5c16f798b301c853ca160 |
|
BLAKE2b-256 | cfd4c5b31cda6af7f237ccd81c66d96d2b49038b408255e65ad6dd783de84cd8 |
Hashes for django_dynamic_allowedsites-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5e34705aa4c214cd88856fdbc987bb8fe54a3252328b0a8490d84c19e200ff |
|
MD5 | 558f7a3c5108a10632a53530f04d60bc |
|
BLAKE2b-256 | c5fe631f40f4e01810a2bd29e516ba25b1bd26786dbecb4b87ca9304e3b15d2b |