Opened 11 years ago

Last modified 11 years ago

#21330 closed New feature

More guidance on default settings in reusable applications is required — at Version 2

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 (last modified by Daniele Procida)

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 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.

Change History (2)

comment:1 by Marc Tamlyn, 11 years ago

There are lots of possible ways to do this, and numerous community projects to provide tools to do it. Personally I don't think any of these are better or worse than each other, I don't think consistency is particularly important, and I'm not sure we should document a recommendation when a standard is not clear. The 'correct' solution to this likely depends on the pluggable app in question.

Take this as a -0 to discussing this in the docs, and likely a -1 to discussing it in a tutorial. How about you write your app so it doesn't need a ton of settings! Or better just has one - like DJ toolbar.

comment:2 by Daniele Procida, 11 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top