Metadata-Version: 2.1
Name: django-dynamic-allowedsites
Version: 0.2.0
Summary: Dynamic ALLOWED_HOSTS based on the configured django.contrib.sites
Home-page: https://github.com/frankyjquintero/django-allowedsites
Author: Keryn Knight && nanuxbe && frankyjquintero
Author-email: python-package@kerynknight.com
License: BSD License
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Framework :: Django
Classifier: Natural Language :: English
Classifier: Environment :: Web Environment
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Description-Content-Type: text/markdown
Requires-Dist: Django (>=1.4)

=============================
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


