Opened 11 years ago
Last modified 11 years ago
#21330 closed New feature
More guidance on default settings in reusable applications is required — at Initial Version
Reported by: | Daniele Procida | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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@override_settings
)
and many are tremendously complex.
loic84's suggestion:
# myapp/settings.py DEFAULT_MYAPP_WIDTH = 100 DEFAULT_MYAPP_HEIGHT = 100 # myapp/views.py from django.conf import settings from myapp.settings import * 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.