All Projects → jakubroztocil → Django Settings Export

jakubroztocil / Django Settings Export

Licence: other
Access Django settings from templates the right way™

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Settings Export

Django Poll App
Django poll app is a full featured polling app. You have to register in this app to show the polls and to vote. If you already voted you can not vote again. Only the owner of a poll can add poll , edit poll, update poll, delete poll , add choice, update choice, delete choice and end a poll. If a poll is ended it can not be voted. Ended poll only shows user the final result of the poll. There is a search option for polls. Also user can filter polls by name, publish date, and by number of voted. Pagination will work even after applying filter.
Stars: ✭ 78 (-53.29%)
Mutual labels:  django-application, django
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+1146.71%)
Mutual labels:  settings, django
Covid19 Dashboard
🦠 Django + Plotly Coronavirus dashboard. Powerful data driven Python web-app, with an awesome UI. Contributions welcomed! Featured on 🕶Awesome-list
Stars: ✭ 100 (-40.12%)
Mutual labels:  django-application, django
Microsite
Full featured and completely customizable django site for organizations.
Stars: ✭ 75 (-55.09%)
Mutual labels:  django-application, django
Patchman
Patchman is a Linux Patch Status Monitoring System
Stars: ✭ 163 (-2.4%)
Mutual labels:  django-application, django
Liquid dl
Liquid-dl is a simple tool for utlities such as FFMPEG, youtube-dl, and scdl. It provides a simple framework with simple point and click options allowing users to just click on what they need and use the bare minimum commands to get the results needed.
Stars: ✭ 78 (-53.29%)
Mutual labels:  django-application, django
Django Pattern Library
UI pattern libraries for Django templates
Stars: ✭ 110 (-34.13%)
Mutual labels:  django-application, django
Thinkdiff
My open source project links, programming and software development related code and tutorials are in this repo. Content types: Python, JavaScript, Dart | Django, React, Flutter, React-Native etc.
Stars: ✭ 65 (-61.08%)
Mutual labels:  django-application, django
Django Dersleri
YouTube Django Dersleri için proje kaynak kodu
Stars: ✭ 135 (-19.16%)
Mutual labels:  django-application, django
Hsreplay.net
🔶 Unleash your Potential!
Stars: ✭ 132 (-20.96%)
Mutual labels:  django-application, django
Awesome Django
Repository mirror of GitLab: https://gitlab.com/rosarior/awesome-django This repository is not monitored for issues, use original at GitLab.
Stars: ✭ 8,527 (+5005.99%)
Mutual labels:  django-application, django
Django Mail Templated
Send emails using Django template system
Stars: ✭ 146 (-12.57%)
Mutual labels:  django, templates
Django Likes
Django app providing view interface to django-secretballot.
Stars: ✭ 72 (-56.89%)
Mutual labels:  django-application, django
Education Backend
Django backend for my info-business website
Stars: ✭ 79 (-52.69%)
Mutual labels:  django-application, django
Awesome Django Cn
Django 优秀资源大全。
Stars: ✭ 1,153 (+590.42%)
Mutual labels:  django-application, django
Banking System
A banking System Created Using Django Python Web Framework
Stars: ✭ 105 (-37.13%)
Mutual labels:  django-application, django
Open Semantic Search Apps
Python/Django based webapps and web user interfaces for search, structure (meta data management like thesaurus, ontologies, annotations and named entities) and data import (ETL like text extraction, OCR and crawling filesystems or websites)
Stars: ✭ 55 (-67.07%)
Mutual labels:  django-application, django
Taggit Selectize
Auto-complete/auto-suggestion for django-taggit (django-taggit + selectize.js)
Stars: ✭ 63 (-62.28%)
Mutual labels:  django-application, django
Django Lockdown
Lock down a Django site or individual views, with configurable preview authorization
Stars: ✭ 123 (-26.35%)
Mutual labels:  django-application, django
Django mail admin
The one and only django app to receive & send mail with templates and multiple configurations.
Stars: ✭ 140 (-16.17%)
Mutual labels:  django-application, django

django-settings-export ##########################

|version| |build| |coverage| |downloads|

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/jakubroztocil/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/jakubroztocil/django-settings-export/blob/master/CHANGELOG.rst>_.

Licence

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

Contact

Jakub Roztocil

.. |build| image:: https://github.com/jakubroztocil/django-settings-export/workflows/Build/badge.svg :target: https://github.com/jakubroztocil/django-settings-export/actions :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/jakubroztocil/django-settings-export.svg?branch=master :target: https://coveralls.io/r/jakubroztocil/django-settings-export?branch=master :alt: Coverage

.. |downloads| image:: https://pepy.tech/badge/django-settings-export/month :target: https://pepy.tech/project/django-settings-export/month :alt: Downloads

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].