dynamic ALLOWED_HOSTS
Project description
Django 1.6+ library for setting your ALLOWED_HOSTS based on the domains in django.contrib.sites and the server’s public IP address which is determined at runtime.
Usage is something like the following, in your settings.py or equivalent:
from allowedsites import AllowedSites ALLOWED_HOSTS = AllowedSites(defaults=('mytestsite.com',), dynamic_public_ip=False, net_timeout=5)
dynamic_public_ip=False
If set True, the server’s public IP address is set for ALLOWED_HOSTS at runtime.
The default is False.
net_timeout=5
The timeout for the network request to get the server’s public IP address.
The default is 5 seconds.
Or, if you want to use your cache backend:
from allowedsites import CachedAllowedSites ALLOWED_HOSTS = CachedAllowedSites(cache_timeout=None)
cache_timeout=None
For how long the cache will last, in seconds.
The default is None, means cache forever.
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 clear_cache class method and an update_cache instance 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.clear_cache, sender=Site, dispatch_uid='clear_allowedsites')
Or:
from django.conf import settings from django.db.models.signals import post_save from django.contrib.sites.models import Site post_save.connect(settings.ALLOWED_HOSTS.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
Built Distributions
File details
Details for the file django_allowedsites_dynamic-0.2.1.tar.gz
.
File metadata
- Download URL: django_allowedsites_dynamic-0.2.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 048c175baec98facf09621403a42394ab6bd0ada58513e483648fd5c4d469025 |
|
MD5 | d428b675f03e193800739a576e18bcdc |
|
BLAKE2b-256 | 0594fa04ef06dd07cbfdc82782512cc0a757776f300cbaffc180ddc14a0ac61b |
File details
Details for the file django_allowedsites_dynamic-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: django_allowedsites_dynamic-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2b9d869989bd2513235fc75d7e3b863f6d479f5de42d2057acf198489bf76a |
|
MD5 | b53ca67a1aaac094d98332483ac14e7b |
|
BLAKE2b-256 | c0095db941a82b19c94df442bfc6547adfbfd39857ed286670f57baf278b032d |
File details
Details for the file django_allowedsites_dynamic-0.2.1-py2-none-any.whl
.
File metadata
- Download URL: django_allowedsites_dynamic-0.2.1-py2-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c47347247abaef04e552cbf513b2ff904323f3f956eeddad4cdccd010a096f |
|
MD5 | d1bb26c2c5380101ba0d087e327a99ae |
|
BLAKE2b-256 | 888c94ac6dfd13d71c26be4529d4b7606a2a7ea56e37a618f10c39f7a0a56cc0 |