App Settings for Django
Project description
Django Pods
Django Pods is a minimalist package that lets you configure default settings for your reusable apps, and allows developers using your apps to override these defaults in their own project settings.
This package is largely inspired by Django Rest Framework and Django AllAuth and adapted to work with Django Applications, but also with any classes extending pods.apps.AppSettings.
Preview
Django Pods allows developers to customise app settings in two ways:
Dictionary style (as per Django Rest Framework):
YOUR_APP = { "SETTING": "VALUE" }
Prefix style:
YOUR_APP_SETTING = "VALUE"
Installation
pip install django-pods
Usage in Reusable Apps
If you are publishing a packaged application, add django-pods to the install_requires of your setup.py:
setup( name="rock_n_roll", install_requires=["django-pods", ...], ... )
Add the AppSettings mixin to your AppConfig implementation in rock_n_roll/apps.py:
from django.apps import AppConfig from pods.apps import AppSettings class RockNRollConfig(AppSettings, AppConfig): name = 'rock_n_roll' verbose_name = "Rock ’n’ roll" # Path to app settings module settings_module = "rock_n_roll.app_settings" # Optional settings_imports = ("CLASS_TO_IMPORT",) # Optional # defaults to the capitalized class name, e.g. ROCK_N_ROLL_CONFIG settings_key = "ROCK_N_ROLL"
Declare your default app settings in rock_n_roll/app_settings.py:
QUESTION = "What is your favourite band?" ANSWER = "The Rolling Stones" CLASS_TO_IMPORT = "path.to.ClassToImport"
Access your settings anywhere in your package:
from django.apps import apps app = apps.get_app_config('rock_n_roll') app.QUESTION # What is your favourite band? app.ANSWER # The Rolling Stomes app.CLASS_TO_IMPORT # <class 'path.to.ClassToImport'>
Settings can also be accessed directly via the class:
from rock_n_roll.apps import RockNRollConfig RockNRollConfig.QUESTION RockNRollConfig.ANSWER RockNRollConfig.CLASS_TO_IMPORT
Usage in Projects
Install the app that uses Django Pods:
pip install rock_n_roll
Add the app to the INSTALLED_APPS of your project/settings.py:
INSTALLED_APPS = ( ... "rock_n_roll", ... )
Override the app’s settings as needed:
# Dictionary style ROCK_N_ROLL = { "ANSWER": "The Beatles", } # Prefix style ROCK_N_ROLL_ANSWER = "The Beatles"
Running Tests
tox
Contributions
All contributions and comments are welcome.
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 Distributions
Built Distribution
File details
Details for the file django_pods-1.1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: django_pods-1.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2360eaa2db04a06c181837afbc933cab5fb3e8a0971553ba70c17b5cb3873410 |
|
MD5 | 03aa87628e812b64be3a0d059e3b027c |
|
BLAKE2b-256 | ba642938a12aeea987d8727f49971de87490eccfe21fab2dcfbdbd5231fcefff |