django-settings-export


Namedjango-settings-export JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/jkbrzt/django-settings-export
SummaryThis Django app allows you to export certain settings to your templates.
upload_time2016-11-06 11:18:58
maintainer
docs_urlNone
authorJakub Roztocil
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ``django-settings-export``
##########################


|version| |travis| |coverage|


Often it is needed to make some of your Django project's settings
accessible from within templates. This app provides a simple mechanism
for doing just that.


**Principles:**

* *Explicit is better than implicit:* Only explicitly listed
  settings keys are exported to templates.
* *Errors should never pass silently:* Accessing an undefined
  or unexported setting key from a template results in an exception.


Tested on Python 2.7+, Django 1.5+.


Installation
============

.. code-block:: bash

    $ pip install django-settings-export


Add ``'django_settings_export.settings_export'`` to
template context processor list in your ``settings.py``:

**Django 1.8 and newer:**

.. code-block:: python

    TEMPLATES = [
        {
            # …
            'OPTIONS': {
                'context_processors': [
                    # …
                    'django_settings_export.settings_export',
                ],
            },
        },
    ]

**Django older than 1.8:**

.. code-block:: python

    TEMPLATE_CONTEXT_PROCESSORS = [
        # [...]
        'django_settings_export.settings_export',
    ]



Usage
=====

All settings that should be made accessible from templates need to be
explicitly listed in ``settings.SETTINGS_EXPORT``:


.. code-block:: python

    # settings.py

    DEBUG = True
    GA_ID = 'UA-00000-0'

    SETTINGS_EXPORT = [
        'DEBUG',
        'GA_ID',
    ]



Now you can access those exported settings from your templates
via ``settings.<KEY>``:


.. code-block:: html

    <!-- template.html -->

    {% if not settings.DEBUG %}
        <script>ga('create', '{{ settings.GA_ID }}', 'auto');</script>
    {% endif %}


The ``settings`` variable is an instance of ``dict`` subclass, so
you use all the methods ``dict`` provides. For example, you can iterate over
the keys and values using , ``settings.keys``, ``settings.values``,
``settings.items``, etc:

.. code-block:: html

    {% for key, value in settings.items %}
        {{ key }}: {{ value }}
    {% endfor %}


Changing the ``settings`` variable name
---------------------------------------

If you wish to change the name of the context variable to something besides
``settings``, add ``SETTINGS_EXPORT_VARIABLE_NAME = 'custom_name'``
to your ``settings.py``. This is useful when some other plugin is already adding
``settings`` to your template contexts.


.. code-block:: python

    # settings.py
    FOO = 'bar'
    SETTINGS_EXPORT = ['FOO']
    SETTINGS_EXPORT_VARIABLE_NAME = 'my_config'



.. code-block:: html

    <!-- template.html -->

    {{ my_config.FOO }}


Exceptions
----------

These custom exceptions can be thrown:

* Listing an undefined setting key in ``SETTINGS_EXPORT`` results in an
  ``UndefinedSettingError``.
* Accessing a unexported setting key on the ``settings`` object in a template
  results in an ``UnexportedSettingError``.

All subclass from ``django_settings_export.SettingsExportError``.




Demo & Tests
------------

See the source code of the bundled
`demo app <https://github.com/jkbrzt/django-settings-export/tree/master/tests>`_.


Development
===========

.. code-block:: bash

    $ cd tests

    # Run demo
    $ python manage.py runserver

    # Run tests on current Python
    $ python manage.py test

    # Run tests on all Pythons
    $ tox


Change Log
==========

See `CHANGELOG <https://github.com/jkbrzt/django-settings-export/blob/master/CHANGELOG.rst>`_.


Licence
=======

BSD. See `LICENCE <https://github.com/jkbrzt/django-settings-export/tree/master/LICENCE>`_ for more details.


Contact
=======


Jakub Roztocil

* http://roztocil.co
* https://github.com/jkbrzt
* https://twitter.com/jkbrzt


.. |travis| image:: https://api.travis-ci.org/jkbrzt/django-settings-export.svg
    :target: http://travis-ci.org/jkbrzt/django-settings-export
    :alt: Build Status of the master branch


.. |version| image:: https://badge.fury.io/py/django-settings-export.svg
    :target: https://pypi.python.org/pypi/django-settings-export
    :alt: PyPi

.. |coverage| image:: https://img.shields.io/coveralls/jkbrzt/django-settings-export.svg?branch=master
    :target: https://coveralls.io/r/jkbrzt/django-settings-export?branch=master
    :alt: Coverage

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jkbrzt/django-settings-export",
    "name": "django-settings-export",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jakub Roztocil",
    "author_email": "jakub@roztocil.co",
    "download_url": "https://files.pythonhosted.org/packages/d6/72/9848a2d631dad70d7ea582540f0619e1a7ecf31b3a117de9d9f2b6b28029/django-settings-export-1.2.1.tar.gz",
    "platform": "",
    "description": "``django-settings-export``\n##########################\n\n\n|version| |travis| |coverage|\n\n\nOften it is needed to make some of your Django project's settings\naccessible from within templates. This app provides a simple mechanism\nfor doing just that.\n\n\n**Principles:**\n\n* *Explicit is better than implicit:* Only explicitly listed\n  settings keys are exported to templates.\n* *Errors should never pass silently:* Accessing an undefined\n  or unexported setting key from a template results in an exception.\n\n\nTested on Python 2.7+, Django 1.5+.\n\n\nInstallation\n============\n\n.. code-block:: bash\n\n    $ pip install django-settings-export\n\n\nAdd ``'django_settings_export.settings_export'`` to\ntemplate context processor list in your ``settings.py``:\n\n**Django 1.8 and newer:**\n\n.. code-block:: python\n\n    TEMPLATES = [\n        {\n            # \u2026\n            'OPTIONS': {\n                'context_processors': [\n                    # \u2026\n                    'django_settings_export.settings_export',\n                ],\n            },\n        },\n    ]\n\n**Django older than 1.8:**\n\n.. code-block:: python\n\n    TEMPLATE_CONTEXT_PROCESSORS = [\n        # [...]\n        'django_settings_export.settings_export',\n    ]\n\n\n\nUsage\n=====\n\nAll settings that should be made accessible from templates need to be\nexplicitly listed in ``settings.SETTINGS_EXPORT``:\n\n\n.. code-block:: python\n\n    # settings.py\n\n    DEBUG = True\n    GA_ID = 'UA-00000-0'\n\n    SETTINGS_EXPORT = [\n        'DEBUG',\n        'GA_ID',\n    ]\n\n\n\nNow you can access those exported settings from your templates\nvia ``settings.<KEY>``:\n\n\n.. code-block:: html\n\n    <!-- template.html -->\n\n    {% if not settings.DEBUG %}\n        <script>ga('create', '{{ settings.GA_ID }}', 'auto');</script>\n    {% endif %}\n\n\nThe ``settings`` variable is an instance of ``dict`` subclass, so\nyou use all the methods ``dict`` provides. For example, you can iterate over\nthe keys and values using , ``settings.keys``, ``settings.values``,\n``settings.items``, etc:\n\n.. code-block:: html\n\n    {% for key, value in settings.items %}\n        {{ key }}: {{ value }}\n    {% endfor %}\n\n\nChanging the ``settings`` variable name\n---------------------------------------\n\nIf you wish to change the name of the context variable to something besides\n``settings``, add ``SETTINGS_EXPORT_VARIABLE_NAME = 'custom_name'``\nto your ``settings.py``. This is useful when some other plugin is already adding\n``settings`` to your template contexts.\n\n\n.. code-block:: python\n\n    # settings.py\n    FOO = 'bar'\n    SETTINGS_EXPORT = ['FOO']\n    SETTINGS_EXPORT_VARIABLE_NAME = 'my_config'\n\n\n\n.. code-block:: html\n\n    <!-- template.html -->\n\n    {{ my_config.FOO }}\n\n\nExceptions\n----------\n\nThese custom exceptions can be thrown:\n\n* Listing an undefined setting key in ``SETTINGS_EXPORT`` results in an\n  ``UndefinedSettingError``.\n* Accessing a unexported setting key on the ``settings`` object in a template\n  results in an ``UnexportedSettingError``.\n\nAll subclass from ``django_settings_export.SettingsExportError``.\n\n\n\n\nDemo & Tests\n------------\n\nSee the source code of the bundled\n`demo app <https://github.com/jkbrzt/django-settings-export/tree/master/tests>`_.\n\n\nDevelopment\n===========\n\n.. code-block:: bash\n\n    $ cd tests\n\n    # Run demo\n    $ python manage.py runserver\n\n    # Run tests on current Python\n    $ python manage.py test\n\n    # Run tests on all Pythons\n    $ tox\n\n\nChange Log\n==========\n\nSee `CHANGELOG <https://github.com/jkbrzt/django-settings-export/blob/master/CHANGELOG.rst>`_.\n\n\nLicence\n=======\n\nBSD. See `LICENCE <https://github.com/jkbrzt/django-settings-export/tree/master/LICENCE>`_ for more details.\n\n\nContact\n=======\n\n\nJakub Roztocil\n\n* http://roztocil.co\n* https://github.com/jkbrzt\n* https://twitter.com/jkbrzt\n\n\n.. |travis| image:: https://api.travis-ci.org/jkbrzt/django-settings-export.svg\n    :target: http://travis-ci.org/jkbrzt/django-settings-export\n    :alt: Build Status of the master branch\n\n\n.. |version| image:: https://badge.fury.io/py/django-settings-export.svg\n    :target: https://pypi.python.org/pypi/django-settings-export\n    :alt: PyPi\n\n.. |coverage| image:: https://img.shields.io/coveralls/jkbrzt/django-settings-export.svg?branch=master\n    :target: https://coveralls.io/r/jkbrzt/django-settings-export?branch=master\n    :alt: Coverage\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "This Django app allows you to export certain settings to your templates.",
    "version": "1.2.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d6729848a2d631dad70d7ea582540f0619e1a7ecf31b3a117de9d9f2b6b28029",
                "md5": "2ba67d2cfdbbdbcd631ccc56ab3381e8",
                "sha256": "fceeae49fc597f654c1217415d8e049fc81c930b7154f5d8f28c432db738ff79"
            },
            "downloads": -1,
            "filename": "django-settings-export-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2ba67d2cfdbbdbcd631ccc56ab3381e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4951,
            "upload_time": "2016-11-06T11:18:58",
            "upload_time_iso_8601": "2016-11-06T11:18:58.000503Z",
            "url": "https://files.pythonhosted.org/packages/d6/72/9848a2d631dad70d7ea582540f0619e1a7ecf31b3a117de9d9f2b6b28029/django-settings-export-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2016-11-06 11:18:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jkbrzt",
    "github_project": "django-settings-export",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-settings-export"
}
        
Elapsed time: 0.26918s