reference.rst 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. =========
  2. Reference
  3. =========
  4. .. currentmodule:: appconf
  5. .. class:: AppConf
  6. A representation of a template tag. For example::
  7. class MyAppConf(AppConf):
  8. SETTING_1 = "one"
  9. SETTING_2 = (
  10. "two",
  11. )
  12. .. method:: configure_*(value)
  13. Method for each of the app settings for custom configuration
  14. which gets the value passed of the class attribute or the
  15. appropriate override value of the :attr:`~appconf.AppConf.Meta.holder`
  16. settings, e.g.::
  17. class MyAppConf(AppConf):
  18. DEPLOYMENT_MODE = "dev"
  19. def configure_deployment_mode(self, value):
  20. if on_production():
  21. value = "prod"
  22. return value
  23. The method **must return** the value to be use for the setting in
  24. question.
  25. .. automethod:: configure
  26. .. autoattribute:: configured_data
  27. The dictionary attribute which can be used to do any further custom
  28. configuration handling in the :meth:`~appconf.AppConf.configure`
  29. method, e.g. if multiple settings depend on each other.
  30. .. class:: AppConf.Meta
  31. An ``AppConf`` takes options via a ``Meta`` inner class::
  32. class MyAppConf(AppConf):
  33. SETTING_1 = "one"
  34. SETTING_2 = (
  35. "two",
  36. )
  37. class Meta:
  38. proxy = False
  39. prefix = 'myapp'
  40. required = ['SETTING_3', 'SETTING_4']
  41. holder = 'django.conf.settings'
  42. .. attribute:: prefix
  43. Explicitly choose a prefix for all settings handled by the
  44. ``AppConf`` class. If not given, the prefix will be the capitalized
  45. class module name.
  46. For example, ``acme`` would turn into settings like
  47. ``ACME_SETTING_1``.
  48. .. attribute:: required
  49. A list of settings that must be defined. If any of the specified
  50. settings are not defined, ``ImproperlyConfigured`` will be raised.
  51. .. versionadded:: 0.6
  52. .. attribute:: holder
  53. The global settings holder to use when looking for overrides and
  54. when setting the configured values.
  55. Defaults to ``'django.conf.settings'``.
  56. .. attribute:: proxy
  57. A boolean, if set to ``True`` will enable proxying attribute access
  58. to the :attr:`~appconf.AppConf.Meta.holder`.