dynamic ALLOWED_HOSTS
Project description
Django 1.6+ library for setting your ALLOWED_HOSTS based on the domains in django.contrib.sites
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-dcors (Cross-Origin Resource Sharing headers) and others. I don’t know.
Copyright (c) 2014, Keryn Knight All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.
This license applies to version 0.1.0 of django-allowedsites.
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
File details
Details for the file django-allowedsites-0.1.0.tar.gz
.
File metadata
- Download URL: django-allowedsites-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c28596b802e65605194c1f3222f873b44efc5d84ca3532d3c266488691b24b4e |
|
MD5 | 894e94c6f39685c399f2df0e4ae2d720 |
|
BLAKE2b-256 | b38c96c98a83493af6a3334eb58c750f468ce7b255519f7e7d225190e2776be1 |