Easy app-specific settings for Django
Project description
Easy app-specific settings for Django.
Installation
To install, run: pip install django-easysettings
Usage
Create a conf.py file within your app’s directory, adding attributes for the default values of your app-specific settings. They will be overridden by any project setting that is provided.
For example:
from easysettings import AppSettings class Settings(AppSettings): MYAPP_WIDGETS = ('foo', 'bar') settings = Settings()
Then in your app, rather than from django.conf import settings, use from myapp.conf import settings. For example:
from myapp.conf import settings def dashboard(request): data = {} for widget in settings.MYAPP_WIDGETS: data[widget] = render_widget(widget) if settings.DEBUG: data['debug_mode'] = True # ...
Isolating Settings when Testing
You can force your app’s tests to use the default project settings rather than any value in the project’s settings configuration module.
Just set settings.isolated = True.
For example, you could use a base test class to do this:
class BaseTest(TestCase): def setUp(self): """ Isolate all application specific settings. """ output = super(BaseTest, self).setUp() settings.isolated = True return output def tearDown(self): """ Restore settings to their original state. """ settings.isolated = False settings.revert() return super(BaseTest, self).tearDown()
As also shown in the example above, you can revert any changes made by calling settings.revert().
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-easysettings-1.1.tar.gz
.
File metadata
- Download URL: django-easysettings-1.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 344efac12275e1d0231c49c6bba23cf19928efd65ffaf9542a05b412eb6e3c67 |
|
MD5 | 62e9986c549b4fce1b86b2ca6ceb184c |
|
BLAKE2b-256 | 3e5e410a9226a34895fc0ea6d92b6c3a1f4bac054b3e83e77d848c78ec0227bd |
File details
Details for the file django_easysettings-1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_easysettings-1.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b00649fd849deec220b6de1513520992cf75bf5b0397715d4352fdf96e4b7edc |
|
MD5 | 2f86cbd4a88567c847b9524fe685d845 |
|
BLAKE2b-256 | 9661c771e8ccbb42706c9ae65be78c58214513649b9681e8e9b9662cf02dbf50 |