| 1 |
=============== |
|---|
| 2 |
Django settings |
|---|
| 3 |
=============== |
|---|
| 4 |
|
|---|
| 5 |
A Django settings file contains all the configuration of your Django |
|---|
| 6 |
installation. This document explains how settings work and which settings are |
|---|
| 7 |
available. |
|---|
| 8 |
|
|---|
| 9 |
The basics |
|---|
| 10 |
========== |
|---|
| 11 |
|
|---|
| 12 |
A settings file is just a Python module with module-level variables. |
|---|
| 13 |
|
|---|
| 14 |
Here are a couple of example settings:: |
|---|
| 15 |
|
|---|
| 16 |
DEBUG = False |
|---|
| 17 |
DEFAULT_FROM_EMAIL = 'webmaster@example.com' |
|---|
| 18 |
TEMPLATE_DIRS = ('/home/templates/mike', '/home/templates/john') |
|---|
| 19 |
|
|---|
| 20 |
Because a settings file is a Python module, the following apply: |
|---|
| 21 |
|
|---|
| 22 |
* It doesn't allow for Python syntax errors. |
|---|
| 23 |
* It can assign settings dynamically using normal Python syntax. |
|---|
| 24 |
For example:: |
|---|
| 25 |
|
|---|
| 26 |
MY_SETTING = [str(i) for i in range(30)] |
|---|
| 27 |
|
|---|
| 28 |
* It can import values from other settings files. |
|---|
| 29 |
|
|---|
| 30 |
Designating the settings |
|---|
| 31 |
======================== |
|---|
| 32 |
|
|---|
| 33 |
When you use Django, you have to tell it which settings you're using. Do this |
|---|
| 34 |
by using an environment variable, ``DJANGO_SETTINGS_MODULE``. |
|---|
| 35 |
|
|---|
| 36 |
The value of ``DJANGO_SETTINGS_MODULE`` should be in Python path syntax, e.g. |
|---|
| 37 |
``mysite.settings``. Note that the settings module should be on the |
|---|
| 38 |
Python `import search path`_. |
|---|
| 39 |
|
|---|
| 40 |
.. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html |
|---|
| 41 |
|
|---|
| 42 |
The django-admin.py utility |
|---|
| 43 |
--------------------------- |
|---|
| 44 |
|
|---|
| 45 |
When using `django-admin.py`_, you can either set the environment variable |
|---|
| 46 |
once, or explicitly pass in the settings module each time you run the utility. |
|---|
| 47 |
|
|---|
| 48 |
Example (Unix Bash shell):: |
|---|
| 49 |
|
|---|
| 50 |
export DJANGO_SETTINGS_MODULE=mysite.settings |
|---|
| 51 |
django-admin.py runserver |
|---|
| 52 |
|
|---|
| 53 |
Example (Windows shell):: |
|---|
| 54 |
|
|---|
| 55 |
set DJANGO_SETTINGS_MODULE=mysite.settings |
|---|
| 56 |
django-admin.py runserver |
|---|
| 57 |
|
|---|
| 58 |
Use the ``--settings`` command-line argument to specify the settings manually:: |
|---|
| 59 |
|
|---|
| 60 |
django-admin.py runserver --settings=mysite.settings |
|---|
| 61 |
|
|---|
| 62 |
.. _django-admin.py: ../django_admin/ |
|---|
| 63 |
|
|---|
| 64 |
On the server (mod_python) |
|---|
| 65 |
-------------------------- |
|---|
| 66 |
|
|---|
| 67 |
In your live server environment, you'll need to tell Apache/mod_python which |
|---|
| 68 |
settings file to use. Do that with ``SetEnv``:: |
|---|
| 69 |
|
|---|
| 70 |
<Location "/mysite/"> |
|---|
| 71 |
SetHandler python-program |
|---|
| 72 |
PythonHandler django.core.handlers.modpython |
|---|
| 73 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 74 |
</Location> |
|---|
| 75 |
|
|---|
| 76 |
Read the `Django mod_python documentation`_ for more information. |
|---|
| 77 |
|
|---|
| 78 |
.. _Django mod_python documentation: ../modpython/ |
|---|
| 79 |
|
|---|
| 80 |
Default settings |
|---|
| 81 |
================ |
|---|
| 82 |
|
|---|
| 83 |
A Django settings file doesn't have to define any settings if it doesn't need |
|---|
| 84 |
to. Each setting has a sensible default value. These defaults live in the file |
|---|
| 85 |
``django/conf/global_settings.py``. |
|---|
| 86 |
|
|---|
| 87 |
Here's the algorithm Django uses in compiling settings: |
|---|
| 88 |
|
|---|
| 89 |
* Load settings from ``global_settings.py``. |
|---|
| 90 |
* Load settings from the specified settings file, overriding the global |
|---|
| 91 |
settings as necessary. |
|---|
| 92 |
|
|---|
| 93 |
Note that a settings file should *not* import from ``global_settings``, because |
|---|
| 94 |
that's redundant. |
|---|
| 95 |
|
|---|
| 96 |
Seeing which settings you've changed |
|---|
| 97 |
------------------------------------ |
|---|
| 98 |
|
|---|
| 99 |
There's an easy way to view which of your settings deviate from the default |
|---|
| 100 |
settings. The command ``python manage.py diffsettings`` displays differences |
|---|
| 101 |
between the current settings file and Django's default settings. |
|---|
| 102 |
|
|---|
| 103 |
For more, see the `diffsettings documentation`_. |
|---|
| 104 |
|
|---|
| 105 |
.. _diffsettings documentation: ../django_admin/#diffsettings |
|---|
| 106 |
|
|---|
| 107 |
Using settings in Python code |
|---|
| 108 |
============================= |
|---|
| 109 |
|
|---|
| 110 |
In your Django apps, use settings by importing the object |
|---|
| 111 |
``django.conf.settings``. Example:: |
|---|
| 112 |
|
|---|
| 113 |
from django.conf import settings |
|---|
| 114 |
|
|---|
| 115 |
if settings.DEBUG: |
|---|
| 116 |
# Do something |
|---|
| 117 |
|
|---|
| 118 |
Note that ``django.conf.settings`` isn't a module -- it's an object. So |
|---|
| 119 |
importing individual settings is not possible:: |
|---|
| 120 |
|
|---|
| 121 |
from django.conf.settings import DEBUG # This won't work. |
|---|
| 122 |
|
|---|
| 123 |
Also note that your code should *not* import from either ``global_settings`` or |
|---|
| 124 |
your own settings file. ``django.conf.settings`` abstracts the concepts of |
|---|
| 125 |
default settings and site-specific settings; it presents a single interface. |
|---|
| 126 |
It also decouples the code that uses settings from the location of your |
|---|
| 127 |
settings. |
|---|
| 128 |
|
|---|
| 129 |
Altering settings at runtime |
|---|
| 130 |
============================ |
|---|
| 131 |
|
|---|
| 132 |
You shouldn't alter settings in your applications at runtime. For example, |
|---|
| 133 |
don't do this in a view:: |
|---|
| 134 |
|
|---|
| 135 |
from django.conf import settings |
|---|
| 136 |
|
|---|
| 137 |
settings.DEBUG = True # Don't do this! |
|---|
| 138 |
|
|---|
| 139 |
The only place you should assign to settings is in a settings file. |
|---|
| 140 |
|
|---|
| 141 |
Security |
|---|
| 142 |
======== |
|---|
| 143 |
|
|---|
| 144 |
Because a settings file contains sensitive information, such as the database |
|---|
| 145 |
password, you should make every attempt to limit access to it. For example, |
|---|
| 146 |
change its file permissions so that only you and your Web server's user can |
|---|
| 147 |
read it. This is especially important in a shared-hosting environment. |
|---|
| 148 |
|
|---|
| 149 |
Available settings |
|---|
| 150 |
================== |
|---|
| 151 |
|
|---|
| 152 |
Here's a full list of all available settings, in alphabetical order, and their |
|---|
| 153 |
default values. |
|---|
| 154 |
|
|---|
| 155 |
ABSOLUTE_URL_OVERRIDES |
|---|
| 156 |
---------------------- |
|---|
| 157 |
|
|---|
| 158 |
Default: ``{}`` (Empty dictionary) |
|---|
| 159 |
|
|---|
| 160 |
A dictionary mapping ``"app_label.model_name"`` strings to functions that take |
|---|
| 161 |
a model object and return its URL. This is a way of overriding |
|---|
| 162 |
``get_absolute_url()`` methods on a per-installation basis. Example:: |
|---|
| 163 |
|
|---|
| 164 |
ABSOLUTE_URL_OVERRIDES = { |
|---|
| 165 |
'blogs.Weblog': lambda o: "/blogs/%s/" % o.slug, |
|---|
| 166 |
'news.Story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug), |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
ADMIN_FOR |
|---|
| 170 |
--------- |
|---|
| 171 |
|
|---|
| 172 |
Default: ``()`` (Empty list) |
|---|
| 173 |
|
|---|
| 174 |
Used for admin-site settings modules, this should be a tuple of settings |
|---|
| 175 |
modules (in the format ``'foo.bar.baz'``) for which this site is an admin. |
|---|
| 176 |
|
|---|
| 177 |
The admin site uses this in its automatically-introspected documentation of |
|---|
| 178 |
models, views and template tags. |
|---|
| 179 |
|
|---|
| 180 |
ADMIN_MEDIA_PREFIX |
|---|
| 181 |
------------------ |
|---|
| 182 |
|
|---|
| 183 |
Default: ``'/media/'`` |
|---|
| 184 |
|
|---|
| 185 |
The URL prefix for admin media -- CSS, JavaScript and images. Make sure to use |
|---|
| 186 |
a trailing slash. |
|---|
| 187 |
|
|---|
| 188 |
ADMINS |
|---|
| 189 |
------ |
|---|
| 190 |
|
|---|
| 191 |
Default: ``()`` (Empty tuple) |
|---|
| 192 |
|
|---|
| 193 |
A tuple that lists people who get code error notifications. When |
|---|
| 194 |
``DEBUG=False`` and a view raises an exception, Django will e-mail these people |
|---|
| 195 |
with the full exception information. Each member of the tuple should be a tuple |
|---|
| 196 |
of (Full name, e-mail address). Example:: |
|---|
| 197 |
|
|---|
| 198 |
(('John', 'john@example.com'), ('Mary', 'mary@example.com')) |
|---|
| 199 |
|
|---|
| 200 |
ALLOWED_INCLUDE_ROOTS |
|---|
| 201 |
--------------------- |
|---|
| 202 |
|
|---|
| 203 |
Default: ``()`` (Empty tuple) |
|---|
| 204 |
|
|---|
| 205 |
A tuple of strings representing allowed prefixes for the ``{% ssi %}`` template |
|---|
| 206 |
tag. This is a security measure, so that template authors can't access files |
|---|
| 207 |
that they shouldn't be accessing. |
|---|
| 208 |
|
|---|
| 209 |
For example, if ``ALLOWED_INCLUDE_ROOTS`` is ``('/home/html', '/var/www')``, |
|---|
| 210 |
then ``{% ssi /home/html/foo.txt %}`` would work, but ``{% ssi /etc/passwd %}`` |
|---|
| 211 |
wouldn't. |
|---|
| 212 |
|
|---|
| 213 |
APPEND_SLASH |
|---|
| 214 |
------------ |
|---|
| 215 |
|
|---|
| 216 |
Default: ``True`` |
|---|
| 217 |
|
|---|
| 218 |
Whether to append trailing slashes to URLs. This is only used if |
|---|
| 219 |
``CommonMiddleware`` is installed (see the `middleware docs`_). See also |
|---|
| 220 |
``PREPEND_WWW``. |
|---|
| 221 |
|
|---|
| 222 |
CACHE_BACKEND |
|---|
| 223 |
------------- |
|---|
| 224 |
|
|---|
| 225 |
Default: ``'simple://'`` |
|---|
| 226 |
|
|---|
| 227 |
The cache backend to use. See the `cache docs`_. |
|---|
| 228 |
|
|---|
| 229 |
CACHE_MIDDLEWARE_KEY_PREFIX |
|---|
| 230 |
|
|---|
| 231 |
Default: ``''`` (Empty string) |
|---|
| 232 |
|
|---|
| 233 |
The cache key prefix that the cache middleware should use. See the |
|---|
| 234 |
`cache docs`_. |
|---|
| 235 |
|
|---|
| 236 |
DATABASE_ENGINE |
|---|
| 237 |
--------------- |
|---|
| 238 |
|
|---|
| 239 |
Default: ``'postgresql'`` |
|---|
| 240 |
|
|---|
| 241 |
Which database backend to use. Either ``'postgresql'``, ``'mysql'``, |
|---|
| 242 |
``'sqlite3'`` or ``'ado_mssql'``. |
|---|
| 243 |
|
|---|
| 244 |
DATABASE_HOST |
|---|
| 245 |
------------- |
|---|
| 246 |
|
|---|
| 247 |
Default: ``''`` (Empty string) |
|---|
| 248 |
|
|---|
| 249 |
Which host to use when connecting to the database. An empty string means |
|---|
| 250 |
localhost. Not used with SQLite. |
|---|
| 251 |
|
|---|
| 252 |
If this value starts with a forward slash (``'/'``) and you're using MySQL, |
|---|
| 253 |
MySQL will connect via a Unix socket to the specified socket. For example:: |
|---|
| 254 |
|
|---|
| 255 |
DATABASE_HOST = '/var/run/mysql' |
|---|
| 256 |
|
|---|
| 257 |
If you're using MySQL and this value *doesn't* start with a forward slash, then |
|---|
| 258 |
this value is assumed to be the host. |
|---|
| 259 |
|
|---|
| 260 |
DATABASE_NAME |
|---|
| 261 |
------------- |
|---|
| 262 |
|
|---|
| 263 |
Default: ``''`` (Empty string) |
|---|
| 264 |
|
|---|
| 265 |
The name of the database to use. For SQLite, it's the full path to the database |
|---|
| 266 |
file. |
|---|
| 267 |
|
|---|
| 268 |
DATABASE_OPTIONS |
|---|
| 269 |
---------------- |
|---|
| 270 |
|
|---|
| 271 |
Default: ``{}`` (Empty dictionary) |
|---|
| 272 |
|
|---|
| 273 |
Extra parameters to use when connecting to the database. Consult backend |
|---|
| 274 |
module's document for available keywords. |
|---|
| 275 |
|
|---|
| 276 |
DATABASE_PASSWORD |
|---|
| 277 |
----------------- |
|---|
| 278 |
|
|---|
| 279 |
Default: ``''`` (Empty string) |
|---|
| 280 |
|
|---|
| 281 |
The password to use when connecting to the database. Not used with SQLite. |
|---|
| 282 |
|
|---|
| 283 |
DATABASE_PORT |
|---|
| 284 |
------------- |
|---|
| 285 |
|
|---|
| 286 |
Default: ``''`` (Empty string) |
|---|
| 287 |
|
|---|
| 288 |
The port to use when connecting to the database. An empty string means the |
|---|
| 289 |
default port. Not used with SQLite. |
|---|
| 290 |
|
|---|
| 291 |
DATABASE_USER |
|---|
| 292 |
------------- |
|---|
| 293 |
|
|---|
| 294 |
Default: ``''`` (Empty string) |
|---|
| 295 |
|
|---|
| 296 |
The username to use when connecting to the database. Not used with SQLite. |
|---|
| 297 |
|
|---|
| 298 |
DATE_FORMAT |
|---|
| 299 |
----------- |
|---|
| 300 |
|
|---|
| 301 |
Default: ``'N j, Y'`` (e.g. ``Feb. 4, 2003``) |
|---|
| 302 |
|
|---|
| 303 |
The default formatting to use for date fields on Django admin change-list |
|---|
| 304 |
pages -- and, possibly, by other parts of the system. See |
|---|
| 305 |
`allowed date format strings`_. |
|---|
| 306 |
|
|---|
| 307 |
See also DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and MONTH_DAY_FORMAT. |
|---|
| 308 |
|
|---|
| 309 |
.. _allowed date format strings: ../templates/#now |
|---|
| 310 |
|
|---|
| 311 |
DATETIME_FORMAT |
|---|
| 312 |
--------------- |
|---|
| 313 |
|
|---|
| 314 |
Default: ``'N j, Y, P'`` (e.g. ``Feb. 4, 2003, 4 p.m.``) |
|---|
| 315 |
|
|---|
| 316 |
The default formatting to use for datetime fields on Django admin change-list |
|---|
| 317 |
pages -- and, possibly, by other parts of the system. See |
|---|
| 318 |
`allowed date format strings`_. |
|---|
| 319 |
|
|---|
| 320 |
See also DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and MONTH_DAY_FORMAT. |
|---|
| 321 |
|
|---|
| 322 |
.. _allowed date format strings: ../templates/#now |
|---|
| 323 |
|
|---|
| 324 |
DEBUG |
|---|
| 325 |
----- |
|---|
| 326 |
|
|---|
| 327 |
Default: ``False`` |
|---|
| 328 |
|
|---|
| 329 |
A boolean that turns on/off debug mode. |
|---|
| 330 |
|
|---|
| 331 |
DEFAULT_CHARSET |
|---|
| 332 |
--------------- |
|---|
| 333 |
|
|---|
| 334 |
Default: ``'utf-8'`` |
|---|
| 335 |
|
|---|
| 336 |
Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't |
|---|
| 337 |
manually specified. Used with ``DEFAULT_CONTENT_TYPE`` to construct the |
|---|
| 338 |
``Content-Type`` header. |
|---|
| 339 |
|
|---|
| 340 |
DEFAULT_CONTENT_TYPE |
|---|
| 341 |
-------------------- |
|---|
| 342 |
|
|---|
| 343 |
Default: ``'text/html'`` |
|---|
| 344 |
|
|---|
| 345 |
Default content type to use for all ``HttpResponse`` objects, if a MIME type |
|---|
| 346 |
isn't manually specified. Used with ``DEFAULT_CHARSET`` to construct the |
|---|
| 347 |
``Content-Type`` header. |
|---|
| 348 |
|
|---|
| 349 |
DEFAULT_FROM_EMAIL |
|---|
| 350 |
------------------ |
|---|
| 351 |
|
|---|
| 352 |
Default: ``'webmaster@localhost'`` |
|---|
| 353 |
|
|---|
| 354 |
Default e-mail address to use for various automated correspondence from the |
|---|
| 355 |
site manager(s). |
|---|
| 356 |
|
|---|
| 357 |
DISALLOWED_USER_AGENTS |
|---|
| 358 |
---------------------- |
|---|
| 359 |
|
|---|
| 360 |
Default: ``()`` (Empty tuple) |
|---|
| 361 |
|
|---|
| 362 |
List of compiled regular expression objects representing User-Agent strings |
|---|
| 363 |
that are not allowed to visit any page, systemwide. Use this for bad |
|---|
| 364 |
robots/crawlers. This is only used if ``CommonMiddleware`` is installed (see |
|---|
| 365 |
the `middleware docs`_). |
|---|
| 366 |
|
|---|
| 367 |
EMAIL_HOST |
|---|
| 368 |
---------- |
|---|
| 369 |
|
|---|
| 370 |
Default: ``'localhost'`` |
|---|
| 371 |
|
|---|
| 372 |
The host to use for sending e-mail. |
|---|
| 373 |
|
|---|
| 374 |
See also ``EMAIL_PORT``. |
|---|
| 375 |
|
|---|
| 376 |
EMAIL_HOST_PASSWORD |
|---|
| 377 |
------------------- |
|---|
| 378 |
|
|---|
| 379 |
Default: ``''`` (Empty string) |
|---|
| 380 |
|
|---|
| 381 |
Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty, |
|---|
| 382 |
Django won't attempt authentication. |
|---|
| 383 |
|
|---|
| 384 |
See also ``EMAIL_HOST_USER``. |
|---|
| 385 |
|
|---|
| 386 |
EMAIL_HOST_USER |
|---|
| 387 |
--------------- |
|---|
| 388 |
|
|---|
| 389 |
Default: ``''`` (Empty string) |
|---|
| 390 |
|
|---|
| 391 |
Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty, |
|---|
| 392 |
Django won't attempt authentication. |
|---|
| 393 |
|
|---|
| 394 |
See also ``EMAIL_HOST_PASSWORD``. |
|---|
| 395 |
|
|---|
| 396 |
EMAIL_PORT |
|---|
| 397 |
---------- |
|---|
| 398 |
|
|---|
| 399 |
Default: ``25`` |
|---|
| 400 |
|
|---|
| 401 |
Port to use for the SMTP server defined in ``EMAIL_HOST``. |
|---|
| 402 |
|
|---|
| 403 |
EMAIL_SUBJECT_PREFIX |
|---|
| 404 |
-------------------- |
|---|
| 405 |
|
|---|
| 406 |
Default: ``'[Django] '`` |
|---|
| 407 |
|
|---|
| 408 |
Subject-line prefix for e-mail messages sent with ``django.core.mail.mail_admins`` |
|---|
| 409 |
or ``django.core.mail.mail_managers``. You'll probably want to include the |
|---|
| 410 |
trailing space. |
|---|
| 411 |
|
|---|
| 412 |
IGNORABLE_404_ENDS |
|---|
| 413 |
------------------ |
|---|
| 414 |
|
|---|
| 415 |
Default: ``('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')`` |
|---|
| 416 |
|
|---|
| 417 |
See also ``IGNORABLE_404_STARTS``. |
|---|
| 418 |
|
|---|
| 419 |
IGNORABLE_404_STARTS |
|---|
| 420 |
-------------------- |
|---|
| 421 |
|
|---|
| 422 |
Default: ``('/cgi-bin/', '/_vti_bin', '/_vti_inf')`` |
|---|
| 423 |
|
|---|
| 424 |
A tuple of strings that specify beginnings of URLs that should be ignored by |
|---|
| 425 |
the 404 e-mailer. See ``SEND_BROKEN_LINK_EMAILS`` and ``IGNORABLE_404_ENDS``. |
|---|
| 426 |
|
|---|
| 427 |
INSTALLED_APPS |
|---|
| 428 |
-------------- |
|---|
| 429 |
|
|---|
| 430 |
Default: ``()`` (Empty tuple) |
|---|
| 431 |
|
|---|
| 432 |
A tuple of strings designating all applications that are enabled in this Django |
|---|
| 433 |
installation. Each string should be a full Python path to a Python package that |
|---|
| 434 |
contains a Django application, as created by `django-admin.py startapp`_. |
|---|
| 435 |
|
|---|
| 436 |
.. _django-admin.py startapp: ../django_admin/#startapp-appname |
|---|
| 437 |
|
|---|
| 438 |
INTERNAL_IPS |
|---|
| 439 |
------------ |
|---|
| 440 |
|
|---|
| 441 |
Default: ``()`` (Empty tuple) |
|---|
| 442 |
|
|---|
| 443 |
A tuple of IP addresses, as strings, that: |
|---|
| 444 |
|
|---|
| 445 |
* See debug comments, when ``DEBUG`` is ``True`` |
|---|
| 446 |
* Receive X headers if the ``XViewMiddleware`` is installed (see the |
|---|
| 447 |
`middleware docs`_) |
|---|
| 448 |
|
|---|
| 449 |
JING_PATH |
|---|
| 450 |
--------- |
|---|
| 451 |
|
|---|
| 452 |
Default: ``'/usr/bin/jing'`` |
|---|
| 453 |
|
|---|
| 454 |
Path to the "Jing" executable. Jing is a RELAX NG validator, and Django uses it |
|---|
| 455 |
to validate each ``XMLField`` in your models. |
|---|
| 456 |
See http://www.thaiopensource.com/relaxng/jing.html . |
|---|
| 457 |
|
|---|
| 458 |
LANGUAGE_CODE |
|---|
| 459 |
------------- |
|---|
| 460 |
|
|---|
| 461 |
Default: ``'en-us'`` |
|---|
| 462 |
|
|---|
| 463 |
A string representing the language code for this installation. This should be |
|---|
| 464 |
in standard language format. For example, U.S. English is ``"en-us"``. See the |
|---|
| 465 |
`internationalization docs`_. |
|---|
| 466 |
|
|---|
| 467 |
.. _internationalization docs: ../i18n/ |
|---|
| 468 |
|
|---|
| 469 |
LANGUAGES |
|---|
| 470 |
--------- |
|---|
| 471 |
|
|---|
| 472 |
Default: A tuple of all available languages. Currently, this is:: |
|---|
| 473 |
|
|---|
| 474 |
LANGUAGES = ( |
|---|
| 475 |
('ar', _('Arabic')), |
|---|
| 476 |
('bn', _('Bengali')), |
|---|
| 477 |
('cs', _('Czech')), |
|---|
| 478 |
('cy', _('Welsh')), |
|---|
| 479 |
('da', _('Danish')), |
|---|
| 480 |
('de', _('German')), |
|---|
| 481 |
('el', _('Greek')), |
|---|
| 482 |
('en', _('English')), |
|---|
| 483 |
('es', _('Spanish')), |
|---|
| 484 |
('es_AR', _('Argentinean Spanish')), |
|---|
| 485 |
('fr', _('French')), |
|---|
| 486 |
('gl', _('Galician')), |
|---|
| 487 |
('hu', _('Hungarian')), |
|---|
| 488 |
('he', _('Hebrew')), |
|---|
| 489 |
('is', _('Icelandic')), |
|---|
| 490 |
('it', _('Italian')), |
|---|
| 491 |
('ja', _('Japanese')), |
|---|
| 492 |
('nl', _('Dutch')), |
|---|
| 493 |
('no', _('Norwegian')), |
|---|
| 494 |
('pt-br', _('Brazilian')), |
|---|
| 495 |
('ro', _('Romanian')), |
|---|
| 496 |
('ru', _('Russian')), |
|---|
| 497 |
('sk', _('Slovak')), |
|---|
| 498 |
('sl', _('Slovenian')), |
|---|
| 499 |
('sr', _('Serbian')), |
|---|
| 500 |
('sv', _('Swedish')), |
|---|
| 501 |
('ta', _('Tamil')), |
|---|
| 502 |
('uk', _('Ukrainian')), |
|---|
| 503 |
('zh-cn', _('Simplified Chinese')), |
|---|
| 504 |
('zh-tw', _('Traditional Chinese')), |
|---|
| 505 |
) |
|---|
| 506 |
|
|---|
| 507 |
A tuple of two-tuples in the format (language code, language name). This |
|---|
| 508 |
specifies which languages are available for language selection. See the |
|---|
| 509 |
`internationalization docs`_ for details. |
|---|
| 510 |
|
|---|
| 511 |
Generally, the default value should suffice. Only set this setting if you want |
|---|
| 512 |
to restrict language selection to a subset of the Django-provided languages. |
|---|
| 513 |
|
|---|
| 514 |
If you define a custom ``LANGUAGES`` setting, it's OK to mark the languages as |
|---|
| 515 |
translation strings (as in the default value displayed above) -- but use a |
|---|
| 516 |
"dummy" ``gettext()`` function, not the one in ``django.utils.translation``. |
|---|
| 517 |
You should *never* import ``django.utils.translation`` from within your |
|---|
| 518 |
settings file, because that module in itself depends on the settings, and that |
|---|
| 519 |
would cause a circular import. |
|---|
| 520 |
|
|---|
| 521 |
The solution is to use a "dummy" ``gettext()`` function. Here's a sample |
|---|
| 522 |
settings file:: |
|---|
| 523 |
|
|---|
| 524 |
gettext = lambda s: s |
|---|
| 525 |
|
|---|
| 526 |
LANGUAGES = ( |
|---|
| 527 |
('de', gettext('German')), |
|---|
| 528 |
('en', gettext('English')), |
|---|
| 529 |
) |
|---|
| 530 |
|
|---|
| 531 |
With this arrangement, ``make-messages.py`` will still find and mark these |
|---|
| 532 |
strings for translation, but the translation won't happen at runtime -- so |
|---|
| 533 |
you'll have to remember to wrap the languages in the *real* ``gettext()`` in |
|---|
| 534 |
any code that uses ``LANGUAGES`` at runtime. |
|---|
| 535 |
|
|---|
| 536 |
MANAGERS |
|---|
| 537 |
-------- |
|---|
| 538 |
|
|---|
| 539 |
Default: ``()`` (Empty tuple) |
|---|
| 540 |
|
|---|
| 541 |
A tuple in the same format as ``ADMINS`` that specifies who should get |
|---|
| 542 |
broken-link notifications when ``SEND_BROKEN_LINK_EMAILS=True``. |
|---|
| 543 |
|
|---|
| 544 |
MEDIA_ROOT |
|---|
| 545 |
---------- |
|---|
| 546 |
|
|---|
| 547 |
Default: ``''`` (Empty string) |
|---|
| 548 |
|
|---|
| 549 |
Absolute path to the directory that holds media for this installation. |
|---|
| 550 |
Example: ``"/home/media/media.lawrence.com/"`` See also ``MEDIA_URL``. |
|---|
| 551 |
|
|---|
| 552 |
MEDIA_URL |
|---|
| 553 |
--------- |
|---|
| 554 |
|
|---|
| 555 |
Default: ``''`` (Empty string) |
|---|
| 556 |
|
|---|
| 557 |
URL that handles the media served from ``MEDIA_ROOT``. |
|---|
| 558 |
Example: ``"http://media.lawrence.com"`` |
|---|
| 559 |
|
|---|
| 560 |
Note that this should have a trailing slash if it has a path component. |
|---|
| 561 |
|
|---|
| 562 |
Good: ``"http://www.example.com/static/"`` |
|---|
| 563 |
Bad: ``"http://www.example.com/static"`` |
|---|
| 564 |
|
|---|
| 565 |
MIDDLEWARE_CLASSES |
|---|
| 566 |
------------------ |
|---|
| 567 |
|
|---|
| 568 |
Default:: |
|---|
| 569 |
|
|---|
| 570 |
("django.contrib.sessions.middleware.SessionMiddleware", |
|---|
| 571 |
"django.contrib.auth.middleware.AuthenticationMiddleware", |
|---|
| 572 |
"django.middleware.common.CommonMiddleware", |
|---|
| 573 |
"django.middleware.doc.XViewMiddleware") |
|---|
| 574 |
|
|---|
| 575 |
A tuple of middleware classes to use. See the `middleware docs`_. |
|---|
| 576 |
|
|---|
| 577 |
MONTH_DAY_FORMAT |
|---|
| 578 |
---------------- |
|---|
| 579 |
|
|---|
| 580 |
Default: ``'F j'`` |
|---|
| 581 |
|
|---|
| 582 |
The default formatting to use for date fields on Django admin change-list |
|---|
| 583 |
pages -- and, possibly, by other parts of the system -- in cases when only the |
|---|
| 584 |
month and day are displayed. |
|---|
| 585 |
|
|---|
| 586 |
For example, when a Django admin change-list page is being filtered by a date |
|---|
| 587 |
drilldown, the header for a given day displays the day and month. Different |
|---|
| 588 |
locales have different formats. For example, U.S. English would say |
|---|
| 589 |
"January 1," whereas Spanish might say "1 Enero." |
|---|
| 590 |
|
|---|
| 591 |
See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT, |
|---|
| 592 |
TIME_FORMAT and YEAR_MONTH_FORMAT. |
|---|
| 593 |
|
|---|
| 594 |
PREPEND_WWW |
|---|
| 595 |
----------- |
|---|
| 596 |
|
|---|
| 597 |
Default: ``False`` |
|---|
| 598 |
|
|---|
| 599 |
Whether to prepend the "www." subdomain to URLs that don't have it. This is |
|---|
| 600 |
only used if ``CommonMiddleware`` is installed (see the `middleware docs`_). |
|---|
| 601 |
See also ``APPEND_SLASH``. |
|---|
| 602 |
|
|---|
| 603 |
PROFANITIES_LIST |
|---|
| 604 |
---------------- |
|---|
| 605 |
|
|---|
| 606 |
A tuple of profanities, as strings, that will trigger a validation error when |
|---|
| 607 |
the ``hasNoProfanities`` validator is called. |
|---|
| 608 |
|
|---|
| 609 |
We don't list the default values here, because that would be profane. To see |
|---|
| 610 |
the default values, see the file ``django/conf/global_settings.py``. |
|---|
| 611 |
|
|---|
| 612 |
ROOT_URLCONF |
|---|
| 613 |
------------ |
|---|
| 614 |
|
|---|
| 615 |
Default: Not defined |
|---|
| 616 |
|
|---|
| 617 |
A string representing the full Python import path to your root URLconf. For example: |
|---|
| 618 |
``"mydjangoapps.urls"``. See `How Django processes a request`_. |
|---|
| 619 |
|
|---|
| 620 |
.. _How Django processes a request: ../url_dispatch/#how-django-processes-a-request |
|---|
| 621 |
|
|---|
| 622 |
SECRET_KEY |
|---|
| 623 |
---------- |
|---|
| 624 |
|
|---|
| 625 |
Default: ``''`` (Empty string) |
|---|
| 626 |
|
|---|
| 627 |
A secret key for this particular Django installation. Used to provide a seed in |
|---|
| 628 |
secret-key hashing algorithms. Set this to a random string -- the longer, the |
|---|
| 629 |
better. ``django-admin.py startproject`` creates one automatically. |
|---|
| 630 |
|
|---|
| 631 |
SEND_BROKEN_LINK_EMAILS |
|---|
| 632 |
----------------------- |
|---|
| 633 |
|
|---|
| 634 |
Default: ``False`` |
|---|
| 635 |
|
|---|
| 636 |
Whether to send an e-mail to the ``MANAGERS`` each time somebody visits a |
|---|
| 637 |
Django-powered page that is 404ed with a non-empty referer (i.e., a broken |
|---|
| 638 |
link). This is only used if ``CommonMiddleware`` is installed (see the |
|---|
| 639 |
`middleware docs`_). See also ``IGNORABLE_404_STARTS`` and |
|---|
| 640 |
``IGNORABLE_404_ENDS``. |
|---|
| 641 |
|
|---|
| 642 |
SERVER_EMAIL |
|---|
| 643 |
------------ |
|---|
| 644 |
|
|---|
| 645 |
Default: ``'root@localhost'`` |
|---|
| 646 |
|
|---|
| 647 |
The e-mail address that error messages come from, such as those sent to |
|---|
| 648 |
``ADMINS`` and ``MANAGERS``. |
|---|
| 649 |
|
|---|
| 650 |
SESSION_COOKIE_AGE |
|---|
| 651 |
------------------ |
|---|
| 652 |
|
|---|
| 653 |
Default: ``1209600`` (2 weeks, in seconds) |
|---|
| 654 |
|
|---|
| 655 |
The age of session cookies, in seconds. See the `session docs`_. |
|---|
| 656 |
|
|---|
| 657 |
SESSION_COOKIE_DOMAIN |
|---|
| 658 |
--------------------- |
|---|
| 659 |
|
|---|
| 660 |
Default: ``None`` |
|---|
| 661 |
|
|---|
| 662 |
The domain to use for session cookies. Set this to a string such as |
|---|
| 663 |
``".lawrence.com"`` for cross-domain cookies, or use ``None`` for a standard |
|---|
| 664 |
domain cookie. See the `session docs`_. |
|---|
| 665 |
|
|---|
| 666 |
SESSION_COOKIE_NAME |
|---|
| 667 |
------------------- |
|---|
| 668 |
|
|---|
| 669 |
Default: ``'sessionid'`` |
|---|
| 670 |
|
|---|
| 671 |
The name of the cookie to use for sessions. This can be whatever you want. |
|---|
| 672 |
See the `session docs`_. |
|---|
| 673 |
|
|---|
| 674 |
SESSION_COOKIE_SECURE |
|---|
| 675 |
--------------------- |
|---|
| 676 |
|
|---|
| 677 |
**New in Django development version** |
|---|
| 678 |
|
|---|
| 679 |
Default: ``False`` |
|---|
| 680 |
|
|---|
| 681 |
Whether to use a secure cookie for the session cookie. If this is set to |
|---|
| 682 |
``True``, the cookie will be marked as "secure," which means browsers may |
|---|
| 683 |
ensure that the cookie is only sent under an HTTPS connection. |
|---|
| 684 |
See the `session docs`_. |
|---|
| 685 |
|
|---|
| 686 |
SESSION_EXPIRE_AT_BROWSER_CLOSE |
|---|
| 687 |
------------------------------- |
|---|
| 688 |
|
|---|
| 689 |
Default: ``False`` |
|---|
| 690 |
|
|---|
| 691 |
Whether to expire the session when the user closes his or her browser. |
|---|
| 692 |
See the `session docs`_. |
|---|
| 693 |
|
|---|
| 694 |
SESSION_SAVE_EVERY_REQUEST |
|---|
| 695 |
-------------------------- |
|---|
| 696 |
|
|---|
| 697 |
Default: ``False`` |
|---|
| 698 |
|
|---|
| 699 |
Whether to save the session data on every request. See the `session docs`_. |
|---|
| 700 |
|
|---|
| 701 |
SITE_ID |
|---|
| 702 |
------- |
|---|
| 703 |
|
|---|
| 704 |
Default: Not defined |
|---|
| 705 |
|
|---|
| 706 |
The ID, as an integer, of the current site in the ``django_site`` database |
|---|
| 707 |
table. This is used so that application data can hook into specific site(s) |
|---|
| 708 |
and a single database can manage content for multiple sites. |
|---|
| 709 |
|
|---|
| 710 |
See the `site framework docs`_. |
|---|
| 711 |
|
|---|
| 712 |
.. _site framework docs: ../sites/ |
|---|
| 713 |
|
|---|
| 714 |
TEMPLATE_CONTEXT_PROCESSORS |
|---|
| 715 |
--------------------------- |
|---|
| 716 |
|
|---|
| 717 |
Default:: |
|---|
| 718 |
|
|---|
| 719 |
("django.core.context_processors.auth", |
|---|
| 720 |
"django.core.context_processors.debug", |
|---|
| 721 |
"django.core.context_processors.i18n") |
|---|
| 722 |
|
|---|
| 723 |
A tuple of callables that are used to populate the context in ``RequestContext``. |
|---|
| 724 |
These callables take a request object as their argument and return a dictionary |
|---|
| 725 |
of items to be merged into the context. |
|---|
| 726 |
|
|---|
| 727 |
TEMPLATE_DEBUG |
|---|
| 728 |
-------------- |
|---|
| 729 |
|
|---|
| 730 |
Default: ``False`` |
|---|
| 731 |
|
|---|
| 732 |
A boolean that turns on/off template debug mode. If this is ``True``, the fancy |
|---|
| 733 |
error page will display a detailed report for any ``TemplateSyntaxError``. This |
|---|
| 734 |
report contains the relevant snippet of the template, with the appropriate line |
|---|
| 735 |
highlighted. |
|---|
| 736 |
|
|---|
| 737 |
Note that Django only displays fancy error pages if ``DEBUG`` is ``True``, so |
|---|
| 738 |
you'll want to set that to take advantage of this setting. |
|---|
| 739 |
|
|---|
| 740 |
See also DEBUG. |
|---|
| 741 |
|
|---|
| 742 |
TEMPLATE_DIRS |
|---|
| 743 |
------------- |
|---|
| 744 |
|
|---|
| 745 |
Default: ``()`` (Empty tuple) |
|---|
| 746 |
|
|---|
| 747 |
List of locations of the template source files, in search order. Note that |
|---|
| 748 |
these paths should use Unix-style forward slashes, even on Windows. |
|---|
| 749 |
|
|---|
| 750 |
See the `template documentation`_. |
|---|
| 751 |
|
|---|
| 752 |
TEMPLATE_LOADERS |
|---|
| 753 |
---------------- |
|---|
| 754 |
|
|---|
| 755 |
Default: ``('django.template.loaders.filesystem.load_template_source',)`` |
|---|
| 756 |
|
|---|
| 757 |
A tuple of callables (as strings) that know how to import templates from |
|---|
| 758 |
various sources. See the `template documentation`_. |
|---|
| 759 |
|
|---|
| 760 |
TEMPLATE_STRING_IF_INVALID |
|---|
| 761 |
-------------------------- |
|---|
| 762 |
|
|---|
| 763 |
Default: ``''`` (Empty string) |
|---|
| 764 |
|
|---|
| 765 |
Output, as a string, that the template system should use for invalid (e.g. |
|---|
| 766 |
misspelled) variables. See `How invalid variables are handled`_. |
|---|
| 767 |
|
|---|
| 768 |
.. _How invalid variables are handled: ../templates_python/#how-invalid-variables-are-handled |
|---|
| 769 |
|
|---|
| 770 |
TEST_RUNNER |
|---|
| 771 |
----------- |
|---|
| 772 |
|
|---|
| 773 |
**New in Django development version** |
|---|
| 774 |
|
|---|
| 775 |
Default: ``'django.test.simple.run_tests'`` |
|---|
| 776 |
|
|---|
| 777 |
The name of the method to use for starting the test suite. See |
|---|
| 778 |
`Testing Django Applications`_. |
|---|
| 779 |
|
|---|
| 780 |
.. _Testing Django Applications: ../testing/ |
|---|
| 781 |
|
|---|
| 782 |
TEST_DATABASE_NAME |
|---|
| 783 |
------------------ |
|---|
| 784 |
|
|---|
| 785 |
**New in Django development version** |
|---|
| 786 |
|
|---|
| 787 |
Default: ``None`` |
|---|
| 788 |
|
|---|
| 789 |
The name of database to use when running the test suite. If a value of |
|---|
| 790 |
``None`` is specified, the test database will use the name ``'test_' + settings.DATABASE_NAME``. See `Testing Django Applications`_. |
|---|
| 791 |
|
|---|
| 792 |
.. _Testing Django Applications: ../testing/ |
|---|
| 793 |
|
|---|
| 794 |
TIME_FORMAT |
|---|
| 795 |
----------- |
|---|
| 796 |
|
|---|
| 797 |
Default: ``'P'`` (e.g. ``4 p.m.``) |
|---|
| 798 |
|
|---|
| 799 |
The default formatting to use for time fields on Django admin change-list |
|---|
| 800 |
pages -- and, possibly, by other parts of the system. See |
|---|
| 801 |
`allowed date format strings`_. |
|---|
| 802 |
|
|---|
| 803 |
See also DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT, YEAR_MONTH_FORMAT and |
|---|
| 804 |
MONTH_DAY_FORMAT. |
|---|
| 805 |
|
|---|
| 806 |
.. _allowed date format strings: ../templates/#now |
|---|
| 807 |
|
|---|
| 808 |
TIME_ZONE |
|---|
| 809 |
--------- |
|---|
| 810 |
|
|---|
| 811 |
Default: ``'America/Chicago'`` |
|---|
| 812 |
|
|---|
| 813 |
A string representing the time zone for this installation. `See available choices`_. |
|---|
| 814 |
(Note that list of available choices lists more than one on the same line; |
|---|
| 815 |
you'll want to use just one of the choices for a given time zone. For instance, |
|---|
| 816 |
one line says ``'Europe/London GB GB-Eire'``, but you should use the first bit |
|---|
| 817 |
of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.) |
|---|
| 818 |
|
|---|
| 819 |
Note that this is the time zone to which Django will convert all dates/times -- |
|---|
| 820 |
not necessarily the timezone of the server. For example, one server may serve |
|---|
| 821 |
multiple Django-powered sites, each with a separate time-zone setting. |
|---|
| 822 |
|
|---|
| 823 |
Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you |
|---|
| 824 |
specify in the ``TIME_ZONE`` setting. Thus, all your views and models will |
|---|
| 825 |
automatically operate in the correct time zone. However, if you're using the |
|---|
| 826 |
manual configuration option (see below), Django will *not* touch the ``TZ`` |
|---|
| 827 |
environment variable, and it'll be up to you to ensure your processes are |
|---|
| 828 |
running in the correct environment. |
|---|
| 829 |
|
|---|
| 830 |
URL_VALIDATOR_USER_AGENT |
|---|
| 831 |
------------------------ |
|---|
| 832 |
|
|---|
| 833 |
Default: ``Django/<version> (http://www.djangoproject.com/)`` |
|---|
| 834 |
|
|---|
| 835 |
The string to use as the ``User-Agent`` header when checking to see if URLs |
|---|
| 836 |
exist (see the ``verify_exists`` option on URLField_). |
|---|
| 837 |
|
|---|
| 838 |
.. _URLField: ../model_api/#urlfield |
|---|
| 839 |
|
|---|
| 840 |
USE_ETAGS |
|---|
| 841 |
--------- |
|---|
| 842 |
|
|---|
| 843 |
Default: ``False`` |
|---|
| 844 |
|
|---|
| 845 |
A boolean that specifies whether to output the "Etag" header. This saves |
|---|
| 846 |
bandwidth but slows down performance. This is only used if ``CommonMiddleware`` |
|---|
| 847 |
is installed (see the `middleware docs`_). |
|---|
| 848 |
|
|---|
| 849 |
USE_I18N |
|---|
| 850 |
-------- |
|---|
| 851 |
|
|---|
| 852 |
Default: ``True`` |
|---|
| 853 |
|
|---|
| 854 |
A boolean that specifies whether Django's internationalization system should be |
|---|
| 855 |
enabled. This provides an easy way to turn it off, for performance. If this is |
|---|
| 856 |
set to ``False``, Django will make some optimizations so as not to load the |
|---|
| 857 |
internationalization machinery. |
|---|
| 858 |
|
|---|
| 859 |
YEAR_MONTH_FORMAT |
|---|
| 860 |
----------------- |
|---|
| 861 |
|
|---|
| 862 |
Default: ``'F Y'`` |
|---|
| 863 |
|
|---|
| 864 |
The default formatting to use for date fields on Django admin change-list |
|---|
| 865 |
pages -- and, possibly, by other parts of the system -- in cases when only the |
|---|
| 866 |
year and month are displayed. |
|---|
| 867 |
|
|---|
| 868 |
For example, when a Django admin change-list page is being filtered by a date |
|---|
| 869 |
drilldown, the header for a given month displays the month and the year. |
|---|
| 870 |
Different locales have different formats. For example, U.S. English would say |
|---|
| 871 |
"January 2006," whereas another locale might say "2006/January." |
|---|
| 872 |
|
|---|
| 873 |
See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT, |
|---|
| 874 |
TIME_FORMAT and MONTH_DAY_FORMAT. |
|---|
| 875 |
|
|---|
| 876 |
.. _cache docs: ../cache/ |
|---|
| 877 |
.. _middleware docs: ../middleware/ |
|---|
| 878 |
.. _session docs: ../sessions/ |
|---|
| 879 |
.. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE |
|---|
| 880 |
.. _template documentation: ../templates_python/ |
|---|
| 881 |
|
|---|
| 882 |
Creating your own settings |
|---|
| 883 |
========================== |
|---|
| 884 |
|
|---|
| 885 |
There's nothing stopping you from creating your own settings, for your own |
|---|
| 886 |
Django apps. Just follow these conventions: |
|---|
| 887 |
|
|---|
| 888 |
* Setting names are in all uppercase. |
|---|
| 889 |
* For settings that are sequences, use tuples instead of lists. This is |
|---|
| 890 |
purely for performance. |
|---|
| 891 |
* Don't reinvent an already-existing setting. |
|---|
| 892 |
|
|---|
| 893 |
Using settings without setting DJANGO_SETTINGS_MODULE |
|---|
| 894 |
===================================================== |
|---|
| 895 |
|
|---|
| 896 |
In some cases, you might want to bypass the ``DJANGO_SETTINGS_MODULE`` |
|---|
| 897 |
environment variable. For example, if you're using the template system by |
|---|
| 898 |
itself, you likely don't want to have to set up an environment variable |
|---|
| 899 |
pointing to a settings module. |
|---|
| 900 |
|
|---|
| 901 |
In these cases, you can configure Django's settings manually. Do this by |
|---|
| 902 |
calling ``django.conf.settings.configure()``. |
|---|
| 903 |
|
|---|
| 904 |
Example:: |
|---|
| 905 |
|
|---|
| 906 |
from django.conf import settings |
|---|
| 907 |
|
|---|
| 908 |
settings.configure(DEBUG=True, TEMPLATE_DEBUG=True, |
|---|
| 909 |
TEMPLATE_DIRS=('/home/web-apps/myapp', '/home/web-apps/base')) |
|---|
| 910 |
|
|---|
| 911 |
Pass ``configure()`` as many keyword arguments as you'd like, with each keyword |
|---|
| 912 |
argument representing a setting and its value. Each argument name should be all |
|---|
| 913 |
uppercase, with the same name as the settings described above. If a particular |
|---|
| 914 |
setting is not passed to ``configure()`` and is needed at some later point, |
|---|
| 915 |
Django will use the default setting value. |
|---|
| 916 |
|
|---|
| 917 |
Configuring Django in this fashion is mostly necessary -- and, indeed, |
|---|
| 918 |
recommended -- when you're using a piece of the framework inside a larger |
|---|
| 919 |
application. |
|---|
| 920 |
|
|---|
| 921 |
Consequently, when configured via ``settings.configure()``, Django will not |
|---|
| 922 |
make any modifications to the process environment variables. (See the |
|---|
| 923 |
explanation of ``TIME_ZONE``, above, for why this would normally occur.) It's |
|---|
| 924 |
assumed that you're already in full control of your environment in these cases. |
|---|
| 925 |
|
|---|
| 926 |
Custom default settings |
|---|
| 927 |
----------------------- |
|---|
| 928 |
|
|---|
| 929 |
If you'd like default values to come from somewhere other than |
|---|
| 930 |
``django.conf.global_settings``, you can pass in a module or class that |
|---|
| 931 |
provides the default settings as the ``default_settings`` argument (or as the |
|---|
| 932 |
first positional argument) in the call to ``configure()``. |
|---|
| 933 |
|
|---|
| 934 |
In this example, default settings are taken from ``myapp_defaults``, and the |
|---|
| 935 |
``DEBUG`` setting is set to ``True``, regardless of its value in |
|---|
| 936 |
``myapp_defaults``:: |
|---|
| 937 |
|
|---|
| 938 |
from django.conf import settings |
|---|
| 939 |
from myapp import myapp_defaults |
|---|
| 940 |
|
|---|
| 941 |
settings.configure(default_settings=myapp_defaults, DEBUG=True) |
|---|
| 942 |
|
|---|
| 943 |
The following example, which uses ``myapp_defaults`` as a positional argument, |
|---|
| 944 |
is equivalent:: |
|---|
| 945 |
|
|---|
| 946 |
settings.configure(myapp_defaults, DEBUG = True) |
|---|
| 947 |
|
|---|
| 948 |
Normally, you will not need to override the defaults in this fashion. The |
|---|
| 949 |
Django defaults are sufficiently tame that you can safely use them. Be aware |
|---|
| 950 |
that if you do pass in a new default module, it entirely *replaces* the Django |
|---|
| 951 |
defaults, so you must specify a value for every possible setting that might be |
|---|
| 952 |
used in that code you are importing. Check in |
|---|
| 953 |
``django.conf.settings.global_settings`` for the full list. |
|---|
| 954 |
|
|---|
| 955 |
Either configure() or DJANGO_SETTINGS_MODULE is required |
|---|
| 956 |
-------------------------------------------------------- |
|---|
| 957 |
|
|---|
| 958 |
If you're not setting the ``DJANGO_SETTINGS_MODULE`` environment variable, you |
|---|
| 959 |
*must* call ``configure()`` at some point before using any code that reads |
|---|
| 960 |
settings. |
|---|
| 961 |
|
|---|
| 962 |
If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``, |
|---|
| 963 |
Django will raise an ``EnvironmentError`` exception the first time a setting |
|---|
| 964 |
is accessed. |
|---|
| 965 |
|
|---|
| 966 |
If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then* |
|---|
| 967 |
call ``configure()``, Django will raise an ``EnvironmentError`` saying settings |
|---|
| 968 |
have already been configured. |
|---|
| 969 |
|
|---|
| 970 |
Also, it's an error to call ``configure()`` more than once, or to call |
|---|
| 971 |
``configure()`` after any setting has been accessed. |
|---|
| 972 |
|
|---|
| 973 |
It boils down to this: Use exactly one of either ``configure()`` or |
|---|
| 974 |
``DJANGO_SETTINGS_MODULE``. Not both, and not neither. |
|---|