Django

Code

root/django/trunk/docs/settings.txt

Revision 7364, 37.1 kB (checked in by mtredinnick, 2 months ago)

Removed the ado_mssql database backend.

It has not been maintained, contains bugs, and improved versions are available
externally(e.g. django-mssql and django-pyodbc at Google code).

  • Property svn:eol-style set to native
Line 
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 Note that the model name used in this setting should be all lower-case, regardless
170 of the case of the actual model class name.
171
172 ADMIN_FOR
173 ---------
174
175 Default: ``()`` (Empty tuple)
176
177 Used for admin-site settings modules, this should be a tuple of settings
178 modules (in the format ``'foo.bar.baz'``) for which this site is an admin.
179
180 The admin site uses this in its automatically-introspected documentation of
181 models, views and template tags.
182
183 ADMIN_MEDIA_PREFIX
184 ------------------
185
186 Default: ``'/media/'``
187
188 The URL prefix for admin media -- CSS, JavaScript and images used by
189 the Django administrative interface. Make sure to use a trailing
190 slash, and to have this be different from the ``MEDIA_URL`` setting
191 (since the same URL cannot be mapped onto two different sets of
192 files).
193
194 ADMINS
195 ------
196
197 Default: ``()`` (Empty tuple)
198
199 A tuple that lists people who get code error notifications. When
200 ``DEBUG=False`` and a view raises an exception, Django will e-mail these people
201 with the full exception information. Each member of the tuple should be a tuple
202 of (Full name, e-mail address). Example::
203
204     (('John', 'john@example.com'), ('Mary', 'mary@example.com'))
205
206 Note that Django will e-mail *all* of these people whenever an error happens. See the
207 section on `error reporting via e-mail`_ for more information.
208
209 ALLOWED_INCLUDE_ROOTS
210 ---------------------
211
212 Default: ``()`` (Empty tuple)
213
214 A tuple of strings representing allowed prefixes for the ``{% ssi %}`` template
215 tag. This is a security measure, so that template authors can't access files
216 that they shouldn't be accessing.
217
218 For example, if ``ALLOWED_INCLUDE_ROOTS`` is ``('/home/html', '/var/www')``,
219 then ``{% ssi /home/html/foo.txt %}`` would work, but ``{% ssi /etc/passwd %}``
220 wouldn't.
221
222 APPEND_SLASH
223 ------------
224
225 Default: ``True``
226
227 Whether to append trailing slashes to URLs. This is only used if
228 ``CommonMiddleware`` is installed (see the `middleware docs`_). See also
229 ``PREPEND_WWW``.
230
231 AUTHENTICATION_BACKENDS
232 -----------------------
233
234 Default: ``('django.contrib.auth.backends.ModelBackend',)``
235
236 A tuple of authentication backend classes (as strings) to use when
237 attempting to authenticate a user. See the `authentication backends
238 documentation`_ for details.
239
240 .. _authentication backends documentation: ../authentication/#other-authentication-sources
241
242 AUTH_PROFILE_MODULE
243 -------------------
244
245 Default: Not defined
246
247 The site-specific user profile model used by this site. See the
248 `documentation on user profile models`_ for details.
249
250 .. _documentation on user profile models: ../authentication/#storing-additional-information-about-users
251
252 CACHE_BACKEND
253 -------------
254
255 Default: ``'simple://'``
256
257 The cache backend to use. See the `cache docs`_.
258
259 CACHE_MIDDLEWARE_KEY_PREFIX
260 ---------------------------
261
262 Default: ``''`` (Empty string)
263
264 The cache key prefix that the cache middleware should use. See the
265 `cache docs`_.
266
267 CACHE_MIDDLEWARE_SECONDS
268 ------------------------
269
270 Default: ``600``
271
272 The default number of seconds to cache a page when the caching middleware or
273 ``cache_page()`` decorator is used.
274
275 DATABASE_ENGINE
276 ---------------
277
278 Default: ``''`` (Empty string)
279
280 The database backend to use. The build-in database backends are
281 ``'postgresql_psycopg2'``, ``'postgresql'``, ``'mysql'``, ``'mysql_old'``,
282 ``'sqlite3'`` and ``'oracle'``.
283
284 In the Django development version, you can use a database backend that doesn't
285 ship with Django by setting ``DATABASE_ENGINE`` to a fully-qualified path (i.e.
286 ``mypackage.backends.whatever``). Writing a whole new database backend from
287 scratch is left as an exercise to the reader; see the other backends for
288 examples.
289
290 DATABASE_HOST
291 -------------
292
293 Default: ``''`` (Empty string)
294
295 Which host to use when connecting to the database. An empty string means
296 localhost. Not used with SQLite.
297
298 If this value starts with a forward slash (``'/'``) and you're using MySQL,
299 MySQL will connect via a Unix socket to the specified socket. For example::
300
301     DATABASE_HOST = '/var/run/mysql'
302
303 If you're using MySQL and this value *doesn't* start with a forward slash, then
304 this value is assumed to be the host.
305
306 If you're using PostgreSQL, an empty string means to use a Unix domain socket
307 for the connection, rather than a network connection to localhost. If you
308 explictly need to use a TCP/IP connection on the local machine with
309 PostgreSQL, specify ``localhost`` here.
310
311 DATABASE_NAME
312 -------------
313
314 Default: ``''`` (Empty string)
315
316 The name of the database to use. For SQLite, it's the full path to the database
317 file.
318
319 DATABASE_OPTIONS
320 ----------------
321
322 Default: ``{}`` (Empty dictionary)
323
324 Extra parameters to use when connecting to the database. Consult backend
325 module's document for available keywords.
326
327 DATABASE_PASSWORD
328 -----------------
329
330 Default: ``''`` (Empty string)
331
332 The password to use when connecting to the database. Not used with SQLite.
333
334 DATABASE_PORT
335 -------------
336
337 Default: ``''`` (Empty string)
338
339 The port to use when connecting to the database. An empty string means the
340 default port. Not used with SQLite.
341
342 DATABASE_USER
343 -------------
344
345 Default: ``''`` (Empty string)
346
347 The username to use when connecting to the database. Not used with SQLite.
348
349 DATE_FORMAT
350 -----------
351
352 Default: ``'N j, Y'`` (e.g. ``Feb. 4, 2003``)
353
354 The default formatting to use for date fields on Django admin change-list
355 pages -- and, possibly, by other parts of the system. See
356 `allowed date format strings`_.
357
358 See also ``DATETIME_FORMAT``, ``TIME_FORMAT``, ``YEAR_MONTH_FORMAT``
359 and ``MONTH_DAY_FORMAT``.
360
361 .. _allowed date format strings: ../templates/#now
362
363 DATETIME_FORMAT
364 ---------------
365
366 Default: ``'N j, Y, P'`` (e.g. ``Feb. 4, 2003, 4 p.m.``)
367
368 The default formatting to use for datetime fields on Django admin change-list
369 pages -- and, possibly, by other parts of the system. See
370 `allowed date format strings`_.
371
372 See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
373 ``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
374
375 .. _allowed date format strings: ../templates/#now
376
377 DEBUG
378 -----
379
380 Default: ``False``
381
382 A boolean that turns on/off debug mode.
383
384 If you define custom settings, django/views/debug.py has a ``HIDDEN_SETTINGS``
385 regular expression which will hide from the DEBUG view anything that contains
386 ``'SECRET'``, ``'PASSWORD'``, or ``'PROFANITIES'``. This allows untrusted users to
387 be able to give backtraces without seeing sensitive (or offensive) settings.
388
389 Still, note that there are always going to be sections of your debug output that
390 are inappropriate for public consumption. File paths, configuration options, and
391 the like all give attackers extra information about your server. Never deploy a
392 site with ``DEBUG`` turned on.
393
394 DEFAULT_CHARSET
395 ---------------
396
397 Default: ``'utf-8'``
398
399 Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't
400 manually specified. Used with ``DEFAULT_CONTENT_TYPE`` to construct the
401 ``Content-Type`` header.
402
403 DEFAULT_CONTENT_TYPE
404 --------------------
405
406 Default: ``'text/html'``
407
408 Default content type to use for all ``HttpResponse`` objects, if a MIME type
409 isn't manually specified. Used with ``DEFAULT_CHARSET`` to construct the
410 ``Content-Type`` header.
411
412 DEFAULT_FROM_EMAIL
413 ------------------
414
415 Default: ``'webmaster@localhost'``
416
417 Default e-mail address to use for various automated correspondence from the
418 site manager(s).
419
420 DEFAULT_TABLESPACE
421 ------------------
422
423 **New in Django development version**
424
425 Default: ``''`` (Empty string)
426
427 Default tablespace to use for models that don't specify one, if the
428 backend supports it.
429
430 DEFAULT_INDEX_TABLESPACE
431 ------------------------
432
433 **New in Django development version**
434
435 Default: ``''`` (Empty string)
436
437 Default tablespace to use for indexes on fields that don't specify
438 one, if the backend supports it.
439
440 DISALLOWED_USER_AGENTS
441 ----------------------
442
443 Default: ``()`` (Empty tuple)
444
445 List of compiled regular expression objects representing User-Agent strings
446 that are not allowed to visit any page, systemwide. Use this for bad
447 robots/crawlers.  This is only used if ``CommonMiddleware`` is installed (see
448 the `middleware docs`_).
449
450 EMAIL_HOST
451 ----------
452
453 Default: ``'localhost'``
454
455 The host to use for sending e-mail.
456
457 See also ``EMAIL_PORT``.
458
459 EMAIL_HOST_PASSWORD
460 -------------------
461
462 Default: ``''`` (Empty string)
463
464 Password to use for the SMTP server defined in ``EMAIL_HOST``. This setting is
465 used in conjunction with ``EMAIL_HOST_USER`` when authenticating to the SMTP
466 server. If either of these settings is empty, Django won't attempt
467 authenticaion.
468
469 See also ``EMAIL_HOST_USER``.
470
471 EMAIL_HOST_USER
472 ---------------
473
474 Default: ``''`` (Empty string)
475
476 Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty,
477 Django won't attempt authentication.
478
479 See also ``EMAIL_HOST_PASSWORD``.
480
481 EMAIL_PORT
482 ----------
483
484 Default: ``25``
485
486 Port to use for the SMTP server defined in ``EMAIL_HOST``.
487
488 EMAIL_SUBJECT_PREFIX
489 --------------------
490
491 Default: ``'[Django] '``
492
493 Subject-line prefix for e-mail messages sent with ``django.core.mail.mail_admins``
494 or ``django.core.mail.mail_managers``. You'll probably want to include the
495 trailing space.
496
497 EMAIL_USE_TLS
498 -------------
499
500 **New in Django development version**
501
502 Default: ``False``
503
504 Whether to use a TLS (secure) connection when talking to the SMTP server.
505
506 FILE_CHARSET
507 ------------
508
509 **New in Django development version**
510
511 Default: ``'utf-8'``
512
513 The character encoding used to decode any files read from disk. This includes
514 template files and initial SQL data files.
515
516 FIXTURE_DIRS
517 -------------
518
519 Default: ``()`` (Empty tuple)
520
521 List of locations of the fixture data files, in search order. Note that
522 these paths should use Unix-style forward slashes, even on Windows. See
523 `Testing Django Applications`_.
524
525 .. _Testing Django Applications: ../testing/
526
527 IGNORABLE_404_ENDS
528 ------------------
529
530 Default: ``('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')``
531
532 See also ``IGNORABLE_404_STARTS`` and ``Error reporting via e-mail``.
533
534 IGNORABLE_404_STARTS
535 --------------------
536
537 Default: ``('/cgi-bin/', '/_vti_bin', '/_vti_inf')``
538
539 A tuple of strings that specify beginnings of URLs that should be ignored by
540 the 404 e-mailer. See ``SEND_BROKEN_LINK_EMAILS``, ``IGNORABLE_404_ENDS`` and
541 the section on `error reporting via e-mail`_.
542
543 INSTALLED_APPS
544 --------------
545
546 Default: ``()`` (Empty tuple)
547
548 A tuple of strings designating all applications that are enabled in this Django
549 installation. Each string should be a full Python path to a Python package that
550 contains a Django application, as created by `django-admin.py startapp`_.
551
552 .. _django-admin.py startapp: ../django-admin/#startapp-appname
553
554 INTERNAL_IPS
555 ------------
556
557 Default: ``()`` (Empty tuple)
558
559 A tuple of IP addresses, as strings, that:
560
561     * See debug comments, when ``DEBUG`` is ``True``
562     * Receive X headers if the ``XViewMiddleware`` is installed (see the
563       `middleware docs`_)
564
565 JING_PATH
566 ---------
567
568 Default: ``'/usr/bin/jing'``
569
570 Path to the "Jing" executable. Jing is a RELAX NG validator, and Django uses it
571 to validate each ``XMLField`` in your models.
572 See http://www.thaiopensource.com/relaxng/jing.html .
573
574 LANGUAGE_CODE
575 -------------
576
577 Default: ``'en-us'``
578
579 A string representing the language code for this installation. This should be
580 in standard language format. For example, U.S. English is ``"en-us"``. See the
581 `internationalization docs`_.
582
583 .. _internationalization docs: ../i18n/
584
585 LANGUAGE_COOKIE_NAME
586 --------------------
587
588 **New in Django development version**
589
590 Default: ``'django_language'``
591
592 The name of the cookie to use for the language cookie. This can be whatever
593 you want (but should be different from ``SESSION_COOKIE_NAME``). See the
594 `internationalization docs`_ for details.
595
596 LANGUAGES
597 ---------
598
599 Default: A tuple of all available languages. This list is continually growing
600 and including a copy here would inevitably become rapidly out of date. You can
601 see the current list of translated languages by looking in
602 ``django/conf/global_settings.py`` (or view the `online source`_).
603
604 .. _online source: http://code.djangoproject.com/browser/django/trunk/django/conf/global_settings.py
605
606 The list is a tuple of two-tuples in the format (language code, language
607 name) -- for example, ``('ja', 'Japanese')``. This specifies which languages
608 are available for language selection. See the `internationalization docs`_ for
609 details.
610
611 Generally, the default value should suffice. Only set this setting if you want
612 to restrict language selection to a subset of the Django-provided languages.
613
614 If you define a custom ``LANGUAGES`` setting, it's OK to mark the languages as
615 translation strings (as in the default value displayed above) -- but use a
616 "dummy" ``gettext()`` function, not the one in ``django.utils.translation``.
617 You should *never* import ``django.utils.translation`` from within your
618 settings file, because that module in itself depends on the settings, and that
619 would cause a circular import.
620
621 The solution is to use a "dummy" ``gettext()`` function. Here's a sample
622 settings file::
623
624     gettext = lambda s: s
625
626     LANGUAGES = (
627         ('de', gettext('German')),
628         ('en', gettext('English')),
629     )
630
631 With this arrangement, ``make-messages.py`` will still find and mark these
632 strings for translation, but the translation won't happen at runtime -- so
633 you'll have to remember to wrap the languages in the *real* ``gettext()`` in
634 any code that uses ``LANGUAGES`` at runtime.
635
636 LOCALE_PATHS
637 ------------
638
639 Default: ``()`` (Empty tuple)
640
641 A tuple of directories where Django looks for translation files.
642 See the `internationalization docs section`_ explaining the variable and the
643 default behavior.
644
645 .. _internationalization docs section: ../i18n/#using-translations-in-your-own-projects
646
647 LOGIN_REDIRECT_URL
648 ------------------
649
650 **New in Django development version**
651
652 Default: ``'/accounts/profile/'``
653
654 The URL where requests are redirected after login when the
655 ``contrib.auth.login`` view gets no ``next`` parameter.
656
657 This is used by the `@login_required`_ decorator, for example.
658
659 LOGIN_URL
660 ---------
661
662 **New in Django development version**
663
664 Default: ``'/accounts/login/'``
665
666 The URL where requests are redirected for login, specially when using the
667 `@login_required`_ decorator.
668
669 LOGOUT_URL
670 ----------
671
672 **New in Django development version**
673
674 Default: ``'/accounts/logout/'``
675
676 LOGIN_URL counterpart.
677
678 MANAGERS
679 --------
680
681 Default: ``()`` (Empty tuple)
682
683 A tuple in the same format as ``ADMINS`` that specifies who should get
684 broken-link notifications when ``SEND_BROKEN_LINK_EMAILS=True``.
685
686 MEDIA_ROOT
687 ----------
688
689 Default: ``''`` (Empty string)
690
691 Absolute path to the directory that holds media for this installation.
692 Example: ``"/home/media/media.lawrence.com/"`` See also ``MEDIA_URL``.
693
694 MEDIA_URL
695 ---------
696
697 Default: ``''`` (Empty string)
698
699 URL that handles the media served from ``MEDIA_ROOT``.
700 Example: ``"http://media.lawrence.com"``
701
702 Note that this should have a trailing slash if it has a path component.
703
704 Good: ``"http://www.example.com/static/"``
705 Bad: ``"http://www.example.com/static"``
706
707 MIDDLEWARE_CLASSES
708 ------------------
709
710 Default::
711
712     ("django.contrib.sessions.middleware.SessionMiddleware",
713      "django.contrib.auth.middleware.AuthenticationMiddleware",
714      "django.middleware.common.CommonMiddleware",
715      "django.middleware.doc.XViewMiddleware")
716
717 A tuple of middleware classes to use. See the `middleware docs`_.
718
719 MONTH_DAY_FORMAT
720 ----------------
721
722 Default: ``'F j'``
723
724 The default formatting to use for date fields on Django admin change-list
725 pages -- and, possibly, by other parts of the system -- in cases when only the
726 month and day are displayed.
727
728 For example, when a Django admin change-list page is being filtered by a date
729 drilldown, the header for a given day displays the day and month. Different
730 locales have different formats. For example, U.S. English would say
731 "January 1," whereas Spanish might say "1 Enero."
732
733 See `allowed date format strings`_. See also ``DATE_FORMAT``,
734 ``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``YEAR_MONTH_FORMAT``.
735
736 PREPEND_WWW
737 -----------
738
739 Default: ``False``
740
741 Whether to prepend the "www." subdomain to URLs that don't have it. This is
742 only used if ``CommonMiddleware`` is installed (see the `middleware docs`_).
743 See also ``APPEND_SLASH``.
744
745 PROFANITIES_LIST
746 ----------------
747
748 A tuple of profanities, as strings, that will trigger a validation error when
749 the ``hasNoProfanities`` validator is called.
750
751 We don't list the default values here, because that would be profane. To see
752 the default values, see the file ``django/conf/global_settings.py``.
753
754 ROOT_URLCONF
755 ------------
756
757 Default: Not defined
758
759 A string representing the full Python import path to your root URLconf. For example:
760 ``"mydjangoapps.urls"``. Can be overridden on a per-request basis by
761 setting the attribute ``urlconf`` on the incoming ``HttpRequest``
762 object. See `How Django processes a request`_ for details.
763
764 .. _How Django processes a request: ../url_dispatch/#how-django-processes-a-request
765
766 SECRET_KEY
767 ----------
768
769 Default: ``''`` (Empty string)
770
771 A secret key for this particular Django installation. Used to provide a seed in
772 secret-key hashing algorithms. Set this to a random string -- the longer, the
773 better. ``django-admin.py startproject`` creates one automatically.
774
775 SEND_BROKEN_LINK_EMAILS
776 -----------------------
777
778 Default: ``False``
779
780 Whether to send an e-mail to the ``MANAGERS`` each time somebody visits a
781 Django-powered page that is 404ed with a non-empty referer (i.e., a broken
782 link). This is only used if ``CommonMiddleware`` is installed (see the
783 `middleware docs`_). See also ``IGNORABLE_404_STARTS``,
784 ``IGNORABLE_404_ENDS`` and the section on `error reporting via e-mail`_
785
786 SERIALIZATION_MODULES
787 ---------------------
788
789 Default: Not defined.
790
791 A dictionary of modules containing serializer definitions (provided as
792 strings), keyed by a string identifier for that serialization type. For
793 example, to define a YAML serializer, use::
794
795     SERIALIZATION_MODULES = { 'yaml' : 'path.to.yaml_serializer' }
796
797 SERVER_EMAIL
798 ------------
799
800 Default: ``'root@localhost'``
801
802 The e-mail address that error messages come from, such as those sent to
803 ``ADMINS`` and ``MANAGERS``.
804
805 SESSION_ENGINE
806 --------------
807
808 **New in Django development version**
809
810 Default: ``django.contrib.sessions.backends.db``
811
812 Controls where Django stores session data. Valid values are:
813
814     * ``'django.contrib.sessions.backends.db'``
815     * ``'django.contrib.sessions.backends.file'``
816     * ``'django.contrib.sessions.backends.cache'``
817
818 See the `session docs`_ for more details.
819
820 SESSION_COOKIE_AGE
821 ------------------
822
823 Default: ``1209600`` (2 weeks, in seconds)
824
825 The age of session cookies, in seconds. See the `session docs`_.
826
827 SESSION_COOKIE_DOMAIN
828 ---------------------
829
830 Default: ``None``
831
832 The domain to use for session cookies. Set this to a string such as
833 ``".lawrence.com"`` for cross-domain cookies, or use ``None`` for a standard
834 domain cookie. See the `session docs`_.
835
836 SESSION_COOKIE_NAME
837 -------------------
838
839 Default: ``'sessionid'``
840
841 The name of the cookie to use for sessions. This can be whatever you want (but
842 should be different from ``LANGUAGE_COOKIE_NAME``). See the `session docs`_.
843
844 SESSION_COOKIE_PATH
845 -------------------
846
847 **New in Django development version**
848
849 Default: ``'/'``
850
851 The path set on the session cookie. This should either match the URL path of your
852 Django installation or be parent of that path.
853
854 This is useful if you have multiple Django instances running under the same
855 hostname. They can use different cookie paths, and each instance will only see
856 its own session cookie.
857
858 SESSION_COOKIE_SECURE
859 ---------------------
860
861 Default: ``False``
862
863 Whether to use a secure cookie for the session cookie. If this is set to
864 ``True``, the cookie will be marked as "secure," which means browsers may
865 ensure that the cookie is only sent under an HTTPS connection.
866 See the `session docs`_.
867
868 SESSION_EXPIRE_AT_BROWSER_CLOSE
869 -------------------------------
870
871 Default: ``False``
872
873 Whether to expire the session when the user closes his or her browser.
874 See the `session docs`_.
875
876 SESSION_FILE_PATH
877 -----------------
878
879 **New in Django development version**
880
881 Default: ``/tmp/``
882
883 If you're using file-based session storage, this sets the directory in
884 which Django will store session data. See the `session docs`_ for
885 more details.
886
887 SESSION_SAVE_EVERY_REQUEST
888 --------------------------
889
890 Default: ``False``
891
892 Whether to save the session data on every request. See the `session docs`_.
893
894 SITE_ID
895 -------
896
897 Default: Not defined
898
899 The ID, as an integer, of the current site in the ``django_site`` database
900 table. This is used so that application data can hook into specific site(s)
901 and a single database can manage content for multiple sites.
902
903 See the `site framework docs`_.
904
905 .. _site framework docs: ../sites/
906
907 TEMPLATE_CONTEXT_PROCESSORS
908 ---------------------------
909
910 Default::
911
912     ("django.core.context_processors.auth",
913     "django.core.context_processors.debug",
914     "django.core.context_processors.i18n",
915     "django.core.context_processors.media")
916
917 A tuple of callables that are used to populate the context in ``RequestContext``.
918 These callables take a request object as their argument and return a dictionary
919 of items to be merged into the context.
920
921 TEMPLATE_DEBUG
922 --------------
923
924 Default: ``False``
925
926 A boolean that turns on/off template debug mode. If this is ``True``, the fancy
927 error page will display a detailed report for any ``TemplateSyntaxError``. This
928 report contains the relevant snippet of the template, with the appropriate line
929 highlighted.
930
931 Note that Django only displays fancy error pages if ``DEBUG`` is ``True``, so
932 you'll want to set that to take advantage of this setting.
933
934 See also ``DEBUG``.
935
936 TEMPLATE_DIRS
937 -------------
938
939 Default: ``()`` (Empty tuple)
940
941 List of locations of the template source files, in search order. Note that
942 these paths should use Unix-style forward slashes, even on Windows.
943
944 See the `template documentation`_.
945
946 TEMPLATE_LOADERS
947 ----------------
948
949 Default: ``('django.template.loaders.filesystem.load_template_source',)``
950
951 A tuple of callables (as strings) that know how to import templates from
952 various sources. See the `template documentation`_.
953
954 TEMPLATE_STRING_IF_INVALID
955 --------------------------
956
957 Default: ``''`` (Empty string)
958
959 Output, as a string, that the template system should use for invalid (e.g.
960 misspelled) variables. See `How invalid variables are handled`_.
961
962 .. _How invalid variables are handled: ../templates_python/#how-invalid-variables-are-handled
963
964 TEST_DATABASE_CHARSET
965 ---------------------
966
967 **New in Django development version**
968
969 Default: ``None``
970
971 The character set encoding used to create the test database. The value of this
972 string is passed directly through to the database, so its format is
973 backend-specific.
974
975 Supported for the PostgreSQL_ (``postgresql``, ``postgresql_psycopg2``) and MySQL_ (``mysql``, ``mysql_old``) backends.
976
977 .. _PostgreSQL: http://www.postgresql.org/docs/8.2/static/multibyte.html
978 .. _MySQL: http://www.mysql.org/doc/refman/5.0/en/charset-database.html
979
980 TEST_DATABASE_COLLATION
981 ------------------------
982
983 **New in Django development version**
984
985 Default: ``None``
986
987 The collation order to use when creating the test database. This value is
988 passed directly to the backend, so its format is backend-specific.
989
990 Only supported for ``mysql`` and ``mysql_old`` backends (see `section 10.3.2`_
991 of the MySQL manual for details).
992
993 .. _section 10.3.2: http://www.mysql.org/doc/refman/5.0/en/charset-database.html
994
995 TEST_DATABASE_NAME
996 ------------------
997
998 Default: ``None``
999
1000 The name of database to use when running the test suite.
1001
1002 If the default value (``None``) is used with the SQLite database engine, the
1003 tests will use a memory resident database. For all other database engines the
1004 test database will use the name ``'test_' + settings.DATABASE_NAME``.
1005
1006 See `Testing Django Applications`_.
1007
1008 .. _Testing Django Applications: ../testing/
1009
1010 TEST_RUNNER
1011 -----------
1012
1013 Default: ``'django.test.simple.run_tests'``
1014
1015 The name of the method to use for starting the test suite. See
1016 `Testing Django Applications`_.
1017
1018 .. _Testing Django Applications: ../testing/
1019
1020 TIME_FORMAT
1021 -----------
1022
1023 Default: ``'P'`` (e.g. ``4 p.m.``)
1024
1025 The default formatting to use for time fields on Django admin change-list
1026 pages -- and, possibly, by other parts of the system. See
1027 `allowed date format strings`_.
1028
1029 See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
1030 ``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
1031
1032 .. _allowed date format strings: ../templates/#now
1033
1034 TIME_ZONE
1035 ---------
1036
1037 Default: ``'America/Chicago'``
1038
1039 A string representing the time zone for this installation. `See available choices`_.
1040 (Note that list of available choices lists more than one on the same line;
1041 you'll want to use just one of the choices for a given time zone. For instance,
1042 one line says ``'Europe/London GB GB-Eire'``, but you should use the first bit
1043 of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
1044
1045 Note that this is the time zone to which Django will convert all dates/times --
1046 not necessarily the timezone of the server. For example, one server may serve
1047 multiple Django-powered sites, each with a separate time-zone setting.
1048
1049 Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
1050 specify in the  ``TIME_ZONE`` setting. Thus, all your views and models will
1051 automatically operate in the correct time zone. However, if you're using the
1052 manual configuration option (see below), Django will *not* touch the ``TZ``
1053 environment variable, and it'll be up to you to ensure your processes are
1054 running in the correct environment.
1055
1056 .. note::
1057     Django cannot reliably use alternate time zones in a Windows environment.
1058     If you're running Django on Windows, this variable must be set to match the
1059     system timezone.
1060
1061 URL_VALIDATOR_USER_AGENT
1062 ------------------------
1063
1064 Default: ``Django/<version> (http://www.djangoproject.com/)``
1065
1066 The string to use as the ``User-Agent`` header when checking to see if URLs
1067 exist (see the ``verify_exists`` option on URLField_).
1068
1069 .. _URLField: ../model-api/#urlfield
1070
1071 USE_ETAGS
1072 ---------
1073
1074 Default: ``False``
1075
1076 A boolean that specifies whether to output the "Etag" header. This saves
1077 bandwidth but slows down performance. This is only used if ``CommonMiddleware``
1078 is installed (see the `middleware docs`_).
1079
1080 USE_I18N
1081 --------
1082
1083 Default: ``True``
1084
1085 A boolean that specifies whether Django's internationalization system should be
1086 enabled. This provides an easy way to turn it off, for performance. If this is
1087 set to ``False``, Django will make some optimizations so as not to load the
1088 internationalization machinery.
1089
1090 YEAR_MONTH_FORMAT
1091 -----------------
1092
1093 Default: ``'F Y'``
1094
1095 The default formatting to use for date fields on Django admin change-list
1096 pages -- and, possibly, by other parts of the system -- in cases when only the
1097 year and month are displayed.
1098
1099 For example, when a Django admin change-list page is being filtered by a date
1100 drilldown, the header for a given month displays the month and the year.
1101 Different locales have different formats. For example, U.S. English would say
1102 "January 2006," whereas another locale might say "2006/January."
1103
1104 See `allowed date format strings`_. See also ``DATE_FORMAT``,
1105 ``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``MONTH_DAY_FORMAT``.
1106
1107 .. _cache docs: ../cache/
1108 .. _middleware docs: ../middleware/
1109 .. _session docs: ../sessions/
1110 .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
1111 .. _template documentation: ../templates_python/
1112
1113 Creating your own settings
1114 ==========================
1115
1116 There's nothing stopping you from creating your own settings, for your own
1117 Django apps. Just follow these conventions:
1118
1119     * Setting names are in all uppercase.
1120     * For settings that are sequences, use tuples instead of lists. This is
1121       purely for performance.
1122     * Don't reinvent an already-existing setting.
1123
1124 Using settings without setting DJANGO_SETTINGS_MODULE
1125 =====================================================
1126
1127 In some cases, you might want to bypass the ``DJANGO_SETTINGS_MODULE``
1128 environment variable. For example, if you're using the template system by
1129 itself, you likely don't want to have to set up an environment variable
1130 pointing to a settings module.
1131
1132 In these cases, you can configure Django's settings manually. Do this by
1133 calling ``django.conf.settings.configure()``.
1134
1135 Example::
1136
1137     from django.conf import settings
1138
1139     settings.configure(DEBUG=True, TEMPLATE_DEBUG=True,
1140         TEMPLATE_DIRS=('/home/web-apps/myapp', '/home/web-apps/base'))
1141
1142 Pass ``configure()`` as many keyword arguments as you'd like, with each keyword
1143 argument representing a setting and its value. Each argument name should be all
1144 uppercase, with the same name as the settings described above. If a particular
1145 setting is not passed to ``configure()`` and is needed at some later point,
1146 Django will use the default setting value.
1147
1148 Configuring Django in this fashion is mostly necessary -- and, indeed,
1149 recommended -- when you're using a piece of the framework inside a larger
1150 application.
1151
1152 Consequently, when configured via ``settings.configure()``, Django will not
1153 make any modifications to the process environment variables. (See the
1154 explanation of ``TIME_ZONE``, above, for why this would normally occur.) It's
1155 assumed that you're already in full control of your environment in these cases.
1156
1157 Custom default settings
1158 -----------------------
1159
1160 If you'd like default values to come from somewhere other than
1161 ``django.conf.global_settings``, you can pass in a module or class that
1162 provides the default settings as the ``default_settings`` argument (or as the
1163 first positional argument) in the call to ``configure()``.
1164
1165 In this example, default settings are taken from ``myapp_defaults``, and the
1166 ``DEBUG`` setting is set to ``True``, regardless of its value in
1167 ``myapp_defaults``::
1168
1169     from django.conf import settings
1170     from myapp import myapp_defaults
1171
1172     settings.configure(default_settings=myapp_defaults, DEBUG=True)
1173
1174 The following example, which uses ``myapp_defaults`` as a positional argument,
1175 is equivalent::
1176
1177     settings.configure(myapp_defaults, DEBUG = True)
1178
1179 Normally, you will not need to override the defaults in this fashion. The
1180 Django defaults are sufficiently tame that you can safely use them. Be aware
1181 that if you do pass in a new default module, it entirely *replaces* the Django
1182 defaults, so you must specify a value for every possible setting that might be
1183 used in that code you are importing. Check in
1184 ``django.conf.settings.global_settings`` for the full list.
1185
1186 Either configure() or DJANGO_SETTINGS_MODULE is required
1187 --------------------------------------------------------
1188
1189 If you're not setting the ``DJANGO_SETTINGS_MODULE`` environment variable, you
1190 *must* call ``configure()`` at some point before using any code that reads
1191 settings.
1192
1193 If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``,
1194 Django will raise an ``ImportError`` exception the first time a setting
1195 is accessed.
1196
1197 If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then*
1198 call ``configure()``, Django will raise a ``RuntimeError`` indicating
1199 that settings have already been configured.
1200
1201 Also, it's an error to call ``configure()`` more than once, or to call
1202 ``configure()`` after any setting has been accessed.
1203
1204 It boils down to this: Use exactly one of either ``configure()`` or
1205 ``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
1206
1207 .. _@login_required: ../authentication/#the-login-required-decorator
1208
1209 Error reporting via e-mail
1210 ==========================
1211
1212 Server errors
1213 -------------
1214
1215 When ``DEBUG`` is ``False``, Django will e-mail the users listed in the
1216 ``ADMIN`` setting whenever your code raises an unhandled exception and results
1217 in an internal server error (HTTP status code 500). This gives the
1218 administrators immediate notification of any errors.
1219
1220 To disable this behavior, just remove all entries from the ``ADMINS`` setting.
1221
1222 404 errors
1223 ----------
1224
1225 When ``DEBUG`` is ``False``, ``SEND_BROKEN_LINK_EMAILS`` is ``True`` and your
1226 ``MIDDLEWARE_CLASSES`` setting includes ``CommonMiddleware``, Django will
1227 e-mail the users listed in the ``MANAGERS`` setting whenever your code raises
1228 a 404 and the request has a referer. (It doesn't bother to e-mail for 404s
1229 that don't have a referer.)
1230
1231 You can tell Django to stop reporting particular 404s by tweaking the
1232 ``IGNORABLE_404_ENDS`` and ``IGNORABLE_404_STARTS`` settings. Both should be a
1233 tuple of strings. For example::
1234
1235     IGNORABLE_404_ENDS = ('.php', '.cgi')
1236     IGNORABLE_404_STARTS = ('/phpmyadmin/',)
1237
1238 In this example, a 404 to any URL ending with ``.php`` or ``.cgi`` will *not*
1239 be reported. Neither will any URL starting with ``/phpmyadmin/``.
1240
1241 To disable this behavior, just remove all entries from the ``MANAGERS`` setting.
Note: See TracBrowser for help on using the browser.