More guidance on default settings in reusable applications is required
|Reported by:||Daniele Procida||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by )
There are numerous different ways of shipping reusable applications with sensible default settings so that the person reusing the application is not obliged to fill settings.py with numerous settings just to get started (if the application requires these settings).
Many of the easy-fix ways that this is done are poor, for example:
- in settings.py,
from app.default_settings import *
- in app.default_settings,
SETTING = getattr(settings, "SETTING", "value")(will cache settings values at module-level; breaks
and many are tremendously complex.
# myapp/settings.py DEFAULT_MYAPP_WIDTH = 100 DEFAULT_MYAPP_HEIGHT = 100 # myapp/views.py from django.conf import settings from myapp.settings import DEFAULT_MYAPP_WIDTH def view(request): print(getattr(settings, 'MYAPP_WIDTH', DEFAULT_MYAPP_WIDTH))
This is simple and robust enough to be recommended in the reusable apps tutorial, and should also be explained more fully along with the problem of module-level settings caching in the settings docs.
There should also be a note in the testing docs warning about how
override_settings can easily be broken.