1.0 beta 1 release notes
[django.git] / docs / settings.txt
blob3b3e908fab780338876034700c4dca0d01e900b4
1 ===============
2 Django settings
3 ===============
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.
9 The basics
10 ==========
12 A settings file is just a Python module with module-level variables.
14 Here are a couple of example settings::
16     DEBUG = False
17     DEFAULT_FROM_EMAIL = 'webmaster@example.com'
18     TEMPLATE_DIRS = ('/home/templates/mike', '/home/templates/john')
20 Because a settings file is a Python module, the following apply:
22     * It doesn't allow for Python syntax errors.
23     * It can assign settings dynamically using normal Python syntax.
24       For example::
26           MY_SETTING = [str(i) for i in range(30)]
28     * It can import values from other settings files.
30 Designating the settings
31 ========================
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``.
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`_.
40 .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
42 The django-admin.py utility
43 ---------------------------
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.
48 Example (Unix Bash shell)::
50     export DJANGO_SETTINGS_MODULE=mysite.settings
51     django-admin.py runserver
53 Example (Windows shell)::
55     set DJANGO_SETTINGS_MODULE=mysite.settings
56     django-admin.py runserver
58 Use the ``--settings`` command-line argument to specify the settings manually::
60     django-admin.py runserver --settings=mysite.settings
62 .. _django-admin.py: ../django-admin/
64 On the server (mod_python)
65 --------------------------
67 In your live server environment, you'll need to tell Apache/mod_python which
68 settings file to use. Do that with ``SetEnv``::
70     <Location "/mysite/">
71         SetHandler python-program
72         PythonHandler django.core.handlers.modpython
73         SetEnv DJANGO_SETTINGS_MODULE mysite.settings
74     </Location>
76 Read the `Django mod_python documentation`_ for more information.
78 .. _Django mod_python documentation: ../modpython/
80 Default settings
81 ================
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``.
87 Here's the algorithm Django uses in compiling settings:
89     * Load settings from ``global_settings.py``.
90     * Load settings from the specified settings file, overriding the global
91       settings as necessary.
93 Note that a settings file should *not* import from ``global_settings``, because
94 that's redundant.
96 Seeing which settings you've changed
97 ------------------------------------
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.
103 For more, see the `diffsettings documentation`_.
105 .. _diffsettings documentation: ../django-admin/#diffsettings
107 Using settings in Python code
108 =============================
110 In your Django apps, use settings by importing the object
111 ``django.conf.settings``. Example::
113     from django.conf import settings
115     if settings.DEBUG:
116         # Do something
118 Note that ``django.conf.settings`` isn't a module -- it's an object. So
119 importing individual settings is not possible::
121     from django.conf.settings import DEBUG  # This won't work.
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.
129 Altering settings at runtime
130 ============================
132 You shouldn't alter settings in your applications at runtime. For example,
133 don't do this in a view::
135     from django.conf import settings
137     settings.DEBUG = True   # Don't do this!
139 The only place you should assign to settings is in a settings file.
141 Security
142 ========
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.
149 Available settings
150 ==================
152 Here's a full list of all available settings, in alphabetical order, and their
153 default values.
155 ABSOLUTE_URL_OVERRIDES
156 ----------------------
158 Default: ``{}`` (Empty dictionary)
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::
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     }
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.
172 ADMIN_FOR
173 ---------
175 Default: ``()`` (Empty tuple)
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.
180 The admin site uses this in its automatically-introspected documentation of
181 models, views and template tags.
183 ADMIN_MEDIA_PREFIX
184 ------------------
186 Default: ``'/media/'``
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).
194 ADMINS
195 ------
197 Default: ``()`` (Empty tuple)
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::
204     (('John', 'john@example.com'), ('Mary', 'mary@example.com'))
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.
209 ALLOWED_INCLUDE_ROOTS
210 ---------------------
212 Default: ``()`` (Empty tuple)
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.
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.
222 APPEND_SLASH
223 ------------
225 Default: ``True``
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``.
231 AUTHENTICATION_BACKENDS
232 -----------------------
234 Default: ``('django.contrib.auth.backends.ModelBackend',)``
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.
240 .. _authentication backends documentation: ../authentication/#other-authentication-sources
242 AUTH_PROFILE_MODULE
243 -------------------
245 Default: Not defined
247 The site-specific user profile model used by this site. See the
248 `documentation on user profile models`_ for details.
250 .. _documentation on user profile models: ../authentication/#storing-additional-information-about-users
252 CACHE_BACKEND
253 -------------
255 Default: ``'locmem://'``
257 The cache backend to use. See the `cache docs`_.
259 CACHE_MIDDLEWARE_KEY_PREFIX
260 ---------------------------
262 Default: ``''`` (Empty string)
264 The cache key prefix that the cache middleware should use. See the
265 `cache docs`_.
267 CACHE_MIDDLEWARE_SECONDS
268 ------------------------
270 Default: ``600``
272 The default number of seconds to cache a page when the caching middleware or
273 ``cache_page()`` decorator is used.
275 DATABASE_ENGINE
276 ---------------
278 Default: ``''`` (Empty string)
280 The database backend to use. The build-in database backends are
281 ``'postgresql_psycopg2'``, ``'postgresql'``, ``'mysql'``, ``'sqlite3'``, and
282 ``'oracle'``.
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.
290 DATABASE_HOST
291 -------------
293 Default: ``''`` (Empty string)
295 Which host to use when connecting to the database. An empty string means
296 localhost. Not used with SQLite.
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::
301     DATABASE_HOST = '/var/run/mysql'
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.
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.
311 DATABASE_NAME
312 -------------
314 Default: ``''`` (Empty string)
316 The name of the database to use. For SQLite, it's the full path to the database
317 file.
319 DATABASE_OPTIONS
320 ----------------
322 Default: ``{}`` (Empty dictionary)
324 Extra parameters to use when connecting to the database. Consult backend
325 module's document for available keywords.
327 DATABASE_PASSWORD
328 -----------------
330 Default: ``''`` (Empty string)
332 The password to use when connecting to the database. Not used with SQLite.
334 DATABASE_PORT
335 -------------
337 Default: ``''`` (Empty string)
339 The port to use when connecting to the database. An empty string means the
340 default port. Not used with SQLite.
342 DATABASE_USER
343 -------------
345 Default: ``''`` (Empty string)
347 The username to use when connecting to the database. Not used with SQLite.
349 DATE_FORMAT
350 -----------
352 Default: ``'N j, Y'`` (e.g. ``Feb. 4, 2003``)
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`_.
358 See also ``DATETIME_FORMAT``, ``TIME_FORMAT``, ``YEAR_MONTH_FORMAT``
359 and ``MONTH_DAY_FORMAT``.
361 .. _allowed date format strings: ../templates/#now
363 DATETIME_FORMAT
364 ---------------
366 Default: ``'N j, Y, P'`` (e.g. ``Feb. 4, 2003, 4 p.m.``)
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`_.
372 See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
373 ``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
375 .. _allowed date format strings: ../templates/#now
377 DEBUG
378 -----
380 Default: ``False``
382 A boolean that turns on/off debug mode.
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.
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. 
393 It is also important to remember that when running with ``DEBUG`` turned on, Django
394 will remember every SQL query it executes. This is useful when you are debugging,
395 but on a production server, it will rapidly consume memory.
397 Never deploy a site into production with ``DEBUG`` turned on.
399 DEBUG_PROPAGATE_EXCEPTIONS
400 --------------------------
402 **New in Django development version**
404 Default: ``False``
406 If set to True, Django's normal exception handling of view functions
407 will be suppressed, and exceptions will propagate upwards.  This can
408 be useful for some test setups, and should never be used on a live
409 site.
411 DEFAULT_CHARSET
412 ---------------
414 Default: ``'utf-8'``
416 Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't
417 manually specified. Used with ``DEFAULT_CONTENT_TYPE`` to construct the
418 ``Content-Type`` header.
420 DEFAULT_CONTENT_TYPE
421 --------------------
423 Default: ``'text/html'``
425 Default content type to use for all ``HttpResponse`` objects, if a MIME type
426 isn't manually specified. Used with ``DEFAULT_CHARSET`` to construct the
427 ``Content-Type`` header.
429 DEFAULT_FILE_STORAGE
430 --------------------
432 Default: ``'django.core.filestorage.filesystem.FileSystemStorage'``
434 Default file storage class to be used for any file-related operations that don't
435 specify a particular storage system. See the `file documentation`_ for details.
437 .. _file documentation: ../files/
439 DEFAULT_FROM_EMAIL
440 ------------------
442 Default: ``'webmaster@localhost'``
444 Default e-mail address to use for various automated correspondence from the
445 site manager(s).
447 DEFAULT_TABLESPACE
448 ------------------
450 **New in Django development version**
452 Default: ``''`` (Empty string)
454 Default tablespace to use for models that don't specify one, if the
455 backend supports it.
457 DEFAULT_INDEX_TABLESPACE
458 ------------------------
460 **New in Django development version**
462 Default: ``''`` (Empty string)
464 Default tablespace to use for indexes on fields that don't specify
465 one, if the backend supports it.
467 DISALLOWED_USER_AGENTS
468 ----------------------
470 Default: ``()`` (Empty tuple)
472 List of compiled regular expression objects representing User-Agent strings
473 that are not allowed to visit any page, systemwide. Use this for bad
474 robots/crawlers.  This is only used if ``CommonMiddleware`` is installed (see
475 the `middleware docs`_).
477 EMAIL_HOST
478 ----------
480 Default: ``'localhost'``
482 The host to use for sending e-mail.
484 See also ``EMAIL_PORT``.
486 EMAIL_HOST_PASSWORD
487 -------------------
489 Default: ``''`` (Empty string)
491 Password to use for the SMTP server defined in ``EMAIL_HOST``. This setting is
492 used in conjunction with ``EMAIL_HOST_USER`` when authenticating to the SMTP
493 server. If either of these settings is empty, Django won't attempt
494 authenticaion.
496 See also ``EMAIL_HOST_USER``.
498 EMAIL_HOST_USER
499 ---------------
501 Default: ``''`` (Empty string)
503 Username to use for the SMTP server defined in ``EMAIL_HOST``. If empty,
504 Django won't attempt authentication.
506 See also ``EMAIL_HOST_PASSWORD``.
508 EMAIL_PORT
509 ----------
511 Default: ``25``
513 Port to use for the SMTP server defined in ``EMAIL_HOST``.
515 EMAIL_SUBJECT_PREFIX
516 --------------------
518 Default: ``'[Django] '``
520 Subject-line prefix for e-mail messages sent with ``django.core.mail.mail_admins``
521 or ``django.core.mail.mail_managers``. You'll probably want to include the
522 trailing space.
524 EMAIL_USE_TLS
525 -------------
527 **New in Django development version**
529 Default: ``False``
531 Whether to use a TLS (secure) connection when talking to the SMTP server.
533 FILE_CHARSET
534 ------------
536 **New in Django development version**
538 Default: ``'utf-8'``
540 The character encoding used to decode any files read from disk. This includes
541 template files and initial SQL data files.
543 FILE_UPLOAD_HANDLERS
544 --------------------
546 **New in Django development version**
548 Default::
550     ("django.core.files.uploadhandler.MemoryFileUploadHandler",
551      "django.core.files.uploadhandler.TemporaryFileUploadHandler",)
553 A tuple of handlers to use for uploading. See `file uploads`_ for details.
555 .. _file uploads: ../upload_handling/
557 FILE_UPLOAD_MAX_MEMORY_SIZE
558 ---------------------------
560 **New in Django development version**
562 Default: ``2621440`` (i.e. 2.5 MB).
564 The maximum size (in bytes) that an upload will be before it gets streamed to
565 the file system. See `file uploads`_ for details.
567 FILE_UPLOAD_TEMP_DIR
568 --------------------
570 **New in Django development version**
572 Default: ``None``
574 The directory to store data temporarily while uploading files. If ``None``,
575 Django will use the standard temporary directory for the operating system. For
576 example, this will default to '/tmp' on \*nix-style operating systems.
578 See `file uploads`_ for details.
580 FIXTURE_DIRS
581 -------------
583 Default: ``()`` (Empty tuple)
585 List of locations of the fixture data files, in search order. Note that
586 these paths should use Unix-style forward slashes, even on Windows. See
587 `Testing Django Applications`_.
589 .. _Testing Django Applications: ../testing/
591 FORCE_SCRIPT_NAME
592 ------------------
594 Default: ``None``
596 If not ``None``, this will be used as the value of the ``SCRIPT_NAME``
597 environment variable in any HTTP request. This setting can be used to override
598 the server-provided value of ``SCRIPT_NAME``, which may be a rewritten version
599 of the preferred value or not supplied at all.
601 IGNORABLE_404_ENDS
602 ------------------
604 Default: ``('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')``
606 See also ``IGNORABLE_404_STARTS`` and ``Error reporting via e-mail``.
608 IGNORABLE_404_STARTS
609 --------------------
611 Default: ``('/cgi-bin/', '/_vti_bin', '/_vti_inf')``
613 A tuple of strings that specify beginnings of URLs that should be ignored by
614 the 404 e-mailer. See ``SEND_BROKEN_LINK_EMAILS``, ``IGNORABLE_404_ENDS`` and
615 the section on `error reporting via e-mail`_.
617 INSTALLED_APPS
618 --------------
620 Default: ``()`` (Empty tuple)
622 A tuple of strings designating all applications that are enabled in this Django
623 installation. Each string should be a full Python path to a Python package that
624 contains a Django application, as created by `django-admin.py startapp`_.
626 .. _django-admin.py startapp: ../django-admin/#startapp-appname
628 INTERNAL_IPS
629 ------------
631 Default: ``()`` (Empty tuple)
633 A tuple of IP addresses, as strings, that:
635     * See debug comments, when ``DEBUG`` is ``True``
636     * Receive X headers if the ``XViewMiddleware`` is installed (see the
637       `middleware docs`_)
639 JING_PATH
640 ---------
642 Default: ``'/usr/bin/jing'``
644 Path to the "Jing" executable. Jing is a RELAX NG validator, and Django uses it
645 to validate each ``XMLField`` in your models.
646 See http://www.thaiopensource.com/relaxng/jing.html .
648 LANGUAGE_CODE
649 -------------
651 Default: ``'en-us'``
653 A string representing the language code for this installation. This should be
654 in standard language format. For example, U.S. English is ``"en-us"``. See the
655 `internationalization docs`_.
657 .. _internationalization docs: ../i18n/
659 LANGUAGE_COOKIE_NAME
660 --------------------
662 **New in Django development version**
664 Default: ``'django_language'``
666 The name of the cookie to use for the language cookie. This can be whatever
667 you want (but should be different from ``SESSION_COOKIE_NAME``). See the
668 `internationalization docs`_ for details.
670 LANGUAGES
671 ---------
673 Default: A tuple of all available languages. This list is continually growing
674 and including a copy here would inevitably become rapidly out of date. You can
675 see the current list of translated languages by looking in
676 ``django/conf/global_settings.py`` (or view the `online source`_).
678 .. _online source: http://code.djangoproject.com/browser/django/trunk/django/conf/global_settings.py
680 The list is a tuple of two-tuples in the format (language code, language
681 name) -- for example, ``('ja', 'Japanese')``. This specifies which languages
682 are available for language selection. See the `internationalization docs`_ for
683 details.
685 Generally, the default value should suffice. Only set this setting if you want
686 to restrict language selection to a subset of the Django-provided languages.
688 If you define a custom ``LANGUAGES`` setting, it's OK to mark the languages as
689 translation strings (as in the default value displayed above) -- but use a
690 "dummy" ``gettext()`` function, not the one in ``django.utils.translation``.
691 You should *never* import ``django.utils.translation`` from within your
692 settings file, because that module in itself depends on the settings, and that
693 would cause a circular import.
695 The solution is to use a "dummy" ``gettext()`` function. Here's a sample
696 settings file::
698     gettext = lambda s: s
700     LANGUAGES = (
701         ('de', gettext('German')),
702         ('en', gettext('English')),
703     )
705 With this arrangement, ``django-admin.py makemessages`` will still find and
706 mark these strings for translation, but the translation won't happen at
707 runtime -- so you'll have to remember to wrap the languages in the *real*
708 ``gettext()`` in any code that uses ``LANGUAGES`` at runtime.
710 LOCALE_PATHS
711 ------------
713 Default: ``()`` (Empty tuple)
715 A tuple of directories where Django looks for translation files.
716 See the `internationalization docs section`_ explaining the variable and the
717 default behavior.
719 .. _internationalization docs section: ../i18n/#using-translations-in-your-own-projects
721 LOGIN_REDIRECT_URL
722 ------------------
724 **New in Django development version**
726 Default: ``'/accounts/profile/'``
728 The URL where requests are redirected after login when the
729 ``contrib.auth.login`` view gets no ``next`` parameter.
731 This is used by the `@login_required`_ decorator, for example.
733 LOGIN_URL
734 ---------
736 **New in Django development version**
738 Default: ``'/accounts/login/'``
740 The URL where requests are redirected for login, specially when using the
741 `@login_required`_ decorator.
743 LOGOUT_URL
744 ----------
746 **New in Django development version**
748 Default: ``'/accounts/logout/'``
750 LOGIN_URL counterpart.
752 MANAGERS
753 --------
755 Default: ``()`` (Empty tuple)
757 A tuple in the same format as ``ADMINS`` that specifies who should get
758 broken-link notifications when ``SEND_BROKEN_LINK_EMAILS=True``.
760 MEDIA_ROOT
761 ----------
763 Default: ``''`` (Empty string)
765 Absolute path to the directory that holds media for this installation.
766 Example: ``"/home/media/media.lawrence.com/"`` See also ``MEDIA_URL``.
768 MEDIA_URL
769 ---------
771 Default: ``''`` (Empty string)
773 URL that handles the media served from ``MEDIA_ROOT``.
774 Example: ``"http://media.lawrence.com"``
776 Note that this should have a trailing slash if it has a path component.
778 Good: ``"http://www.example.com/static/"``
779 Bad: ``"http://www.example.com/static"``
781 MIDDLEWARE_CLASSES
782 ------------------
784 Default::
786     ("django.contrib.sessions.middleware.SessionMiddleware",
787      "django.contrib.auth.middleware.AuthenticationMiddleware",
788      "django.middleware.common.CommonMiddleware",
789      "django.middleware.doc.XViewMiddleware")
791 A tuple of middleware classes to use. See the `middleware docs`_.
793 MONTH_DAY_FORMAT
794 ----------------
796 Default: ``'F j'``
798 The default formatting to use for date fields on Django admin change-list
799 pages -- and, possibly, by other parts of the system -- in cases when only the
800 month and day are displayed.
802 For example, when a Django admin change-list page is being filtered by a date
803 drilldown, the header for a given day displays the day and month. Different
804 locales have different formats. For example, U.S. English would say
805 "January 1," whereas Spanish might say "1 Enero."
807 See `allowed date format strings`_. See also ``DATE_FORMAT``,
808 ``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``YEAR_MONTH_FORMAT``.
810 PREPEND_WWW
811 -----------
813 Default: ``False``
815 Whether to prepend the "www." subdomain to URLs that don't have it. This is
816 only used if ``CommonMiddleware`` is installed (see the `middleware docs`_).
817 See also ``APPEND_SLASH``.
819 PROFANITIES_LIST
820 ----------------
822 A tuple of profanities, as strings, that will trigger a validation error when
823 the ``hasNoProfanities`` validator is called.
825 We don't list the default values here, because that would be profane. To see
826 the default values, see the file ``django/conf/global_settings.py``.
828 ROOT_URLCONF
829 ------------
831 Default: Not defined
833 A string representing the full Python import path to your root URLconf. For example:
834 ``"mydjangoapps.urls"``. Can be overridden on a per-request basis by
835 setting the attribute ``urlconf`` on the incoming ``HttpRequest``
836 object. See `How Django processes a request`_ for details.
838 .. _How Django processes a request: ../url_dispatch/#how-django-processes-a-request
840 SECRET_KEY
841 ----------
843 Default: ``''`` (Empty string)
845 A secret key for this particular Django installation. Used to provide a seed in
846 secret-key hashing algorithms. Set this to a random string -- the longer, the
847 better. ``django-admin.py startproject`` creates one automatically.
849 SEND_BROKEN_LINK_EMAILS
850 -----------------------
852 Default: ``False``
854 Whether to send an e-mail to the ``MANAGERS`` each time somebody visits a
855 Django-powered page that is 404ed with a non-empty referer (i.e., a broken
856 link). This is only used if ``CommonMiddleware`` is installed (see the
857 `middleware docs`_). See also ``IGNORABLE_404_STARTS``,
858 ``IGNORABLE_404_ENDS`` and the section on `error reporting via e-mail`_
860 SERIALIZATION_MODULES
861 ---------------------
863 Default: Not defined.
865 A dictionary of modules containing serializer definitions (provided as
866 strings), keyed by a string identifier for that serialization type. For
867 example, to define a YAML serializer, use::
869     SERIALIZATION_MODULES = { 'yaml' : 'path.to.yaml_serializer' }
871 SERVER_EMAIL
872 ------------
874 Default: ``'root@localhost'``
876 The e-mail address that error messages come from, such as those sent to
877 ``ADMINS`` and ``MANAGERS``.
879 SESSION_ENGINE
880 --------------
882 **New in Django development version**
884 Default: ``django.contrib.sessions.backends.db``
886 Controls where Django stores session data. Valid values are:
888     * ``'django.contrib.sessions.backends.db'``
889     * ``'django.contrib.sessions.backends.file'``
890     * ``'django.contrib.sessions.backends.cache'``
892 See the `session docs`_ for more details.
894 SESSION_COOKIE_AGE
895 ------------------
897 Default: ``1209600`` (2 weeks, in seconds)
899 The age of session cookies, in seconds. See the `session docs`_.
901 SESSION_COOKIE_DOMAIN
902 ---------------------
904 Default: ``None``
906 The domain to use for session cookies. Set this to a string such as
907 ``".lawrence.com"`` for cross-domain cookies, or use ``None`` for a standard
908 domain cookie. See the `session docs`_.
910 SESSION_COOKIE_NAME
911 -------------------
913 Default: ``'sessionid'``
915 The name of the cookie to use for sessions. This can be whatever you want (but
916 should be different from ``LANGUAGE_COOKIE_NAME``). See the `session docs`_.
918 SESSION_COOKIE_PATH
919 -------------------
921 **New in Django development version**
923 Default: ``'/'``
925 The path set on the session cookie. This should either match the URL path of your
926 Django installation or be parent of that path.
928 This is useful if you have multiple Django instances running under the same
929 hostname. They can use different cookie paths, and each instance will only see
930 its own session cookie.
932 SESSION_COOKIE_SECURE
933 ---------------------
935 Default: ``False``
937 Whether to use a secure cookie for the session cookie. If this is set to
938 ``True``, the cookie will be marked as "secure," which means browsers may
939 ensure that the cookie is only sent under an HTTPS connection.
940 See the `session docs`_.
942 SESSION_EXPIRE_AT_BROWSER_CLOSE
943 -------------------------------
945 Default: ``False``
947 Whether to expire the session when the user closes his or her browser.
948 See the `session docs`_.
950 SESSION_FILE_PATH
951 -----------------
953 **New in Django development version**
955 Default: ``/tmp/``
957 If you're using file-based session storage, this sets the directory in
958 which Django will store session data. See the `session docs`_ for
959 more details.
961 SESSION_SAVE_EVERY_REQUEST
962 --------------------------
964 Default: ``False``
966 Whether to save the session data on every request. See the `session docs`_.
968 SITE_ID
969 -------
971 Default: Not defined
973 The ID, as an integer, of the current site in the ``django_site`` database
974 table. This is used so that application data can hook into specific site(s)
975 and a single database can manage content for multiple sites.
977 See the `site framework docs`_.
979 .. _site framework docs: ../sites/
981 TEMPLATE_CONTEXT_PROCESSORS
982 ---------------------------
984 Default::
986     ("django.core.context_processors.auth",
987     "django.core.context_processors.debug",
988     "django.core.context_processors.i18n",
989     "django.core.context_processors.media")
991 A tuple of callables that are used to populate the context in ``RequestContext``.
992 These callables take a request object as their argument and return a dictionary
993 of items to be merged into the context.
995 TEMPLATE_DEBUG
996 --------------
998 Default: ``False``
1000 A boolean that turns on/off template debug mode. If this is ``True``, the fancy
1001 error page will display a detailed report for any ``TemplateSyntaxError``. This
1002 report contains the relevant snippet of the template, with the appropriate line
1003 highlighted.
1005 Note that Django only displays fancy error pages if ``DEBUG`` is ``True``, so
1006 you'll want to set that to take advantage of this setting.
1008 See also ``DEBUG``.
1010 TEMPLATE_DIRS
1011 -------------
1013 Default: ``()`` (Empty tuple)
1015 List of locations of the template source files, in search order. Note that
1016 these paths should use Unix-style forward slashes, even on Windows.
1018 See the `template documentation`_.
1020 TEMPLATE_LOADERS
1021 ----------------
1023 Default::
1025      ('django.template.loaders.filesystem.load_template_source',
1026       'django.template.loaders.app_directories.load_template_source')
1028 A tuple of callables (as strings) that know how to import templates from
1029 various sources. See the `template documentation`_.
1031 TEMPLATE_STRING_IF_INVALID
1032 --------------------------
1034 Default: ``''`` (Empty string)
1036 Output, as a string, that the template system should use for invalid (e.g.
1037 misspelled) variables. See `How invalid variables are handled`_.
1039 .. _How invalid variables are handled: ../templates_python/#how-invalid-variables-are-handled
1041 TEST_DATABASE_CHARSET
1042 ---------------------
1044 **New in Django development version**
1046 Default: ``None``
1048 The character set encoding used to create the test database. The value of this
1049 string is passed directly through to the database, so its format is
1050 backend-specific.
1052 Supported for the PostgreSQL_ (``postgresql``, ``postgresql_psycopg2``) and MySQL_ (``mysql``) backends.
1054 .. _PostgreSQL: http://www.postgresql.org/docs/8.2/static/multibyte.html
1055 .. _MySQL: http://www.mysql.org/doc/refman/5.0/en/charset-database.html
1057 TEST_DATABASE_COLLATION
1058 ------------------------
1060 **New in Django development version**
1062 Default: ``None``
1064 The collation order to use when creating the test database. This value is
1065 passed directly to the backend, so its format is backend-specific.
1067 Only supported for the ``mysql`` backend (see `section 10.3.2`_ of the MySQL
1068 manual for details).
1070 .. _section 10.3.2: http://www.mysql.org/doc/refman/5.0/en/charset-database.html
1072 TEST_DATABASE_NAME
1073 ------------------
1075 Default: ``None``
1077 The name of database to use when running the test suite.
1079 If the default value (``None``) is used with the SQLite database engine, the
1080 tests will use a memory resident database. For all other database engines the
1081 test database will use the name ``'test_' + settings.DATABASE_NAME``.
1083 See `Testing Django Applications`_.
1085 .. _Testing Django Applications: ../testing/
1087 TEST_RUNNER
1088 -----------
1090 Default: ``'django.test.simple.run_tests'``
1092 The name of the method to use for starting the test suite. See
1093 `Testing Django Applications`_.
1095 .. _Testing Django Applications: ../testing/
1097 TIME_FORMAT
1098 -----------
1100 Default: ``'P'`` (e.g. ``4 p.m.``)
1102 The default formatting to use for time fields on Django admin change-list
1103 pages -- and, possibly, by other parts of the system. See
1104 `allowed date format strings`_.
1106 See also ``DATE_FORMAT``, ``DATETIME_FORMAT``, ``TIME_FORMAT``,
1107 ``YEAR_MONTH_FORMAT`` and ``MONTH_DAY_FORMAT``.
1109 .. _allowed date format strings: ../templates/#now
1111 TIME_ZONE
1112 ---------
1114 Default: ``'America/Chicago'``
1116 A string representing the time zone for this installation. `See available choices`_.
1117 (Note that list of available choices lists more than one on the same line;
1118 you'll want to use just one of the choices for a given time zone. For instance,
1119 one line says ``'Europe/London GB GB-Eire'``, but you should use the first bit
1120 of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
1122 Note that this is the time zone to which Django will convert all dates/times --
1123 not necessarily the timezone of the server. For example, one server may serve
1124 multiple Django-powered sites, each with a separate time-zone setting.
1126 Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
1127 specify in the  ``TIME_ZONE`` setting. Thus, all your views and models will
1128 automatically operate in the correct time zone. However, if you're using the
1129 manual configuration option (see below), Django will *not* touch the ``TZ``
1130 environment variable, and it'll be up to you to ensure your processes are
1131 running in the correct environment.
1133 .. note::
1134     Django cannot reliably use alternate time zones in a Windows environment.
1135     If you're running Django on Windows, this variable must be set to match the
1136     system timezone.
1138 URL_VALIDATOR_USER_AGENT
1139 ------------------------
1141 Default: ``Django/<version> (http://www.djangoproject.com/)``
1143 The string to use as the ``User-Agent`` header when checking to see if URLs
1144 exist (see the ``verify_exists`` option on URLField_).
1146 .. _URLField: ../model-api/#urlfield
1148 USE_ETAGS
1149 ---------
1151 Default: ``False``
1153 A boolean that specifies whether to output the "Etag" header. This saves
1154 bandwidth but slows down performance. This is only used if ``CommonMiddleware``
1155 is installed (see the `middleware docs`_).
1157 USE_I18N
1158 --------
1160 Default: ``True``
1162 A boolean that specifies whether Django's internationalization system should be
1163 enabled. This provides an easy way to turn it off, for performance. If this is
1164 set to ``False``, Django will make some optimizations so as not to load the
1165 internationalization machinery.
1167 YEAR_MONTH_FORMAT
1168 -----------------
1170 Default: ``'F Y'``
1172 The default formatting to use for date fields on Django admin change-list
1173 pages -- and, possibly, by other parts of the system -- in cases when only the
1174 year and month are displayed.
1176 For example, when a Django admin change-list page is being filtered by a date
1177 drilldown, the header for a given month displays the month and the year.
1178 Different locales have different formats. For example, U.S. English would say
1179 "January 2006," whereas another locale might say "2006/January."
1181 See `allowed date format strings`_. See also ``DATE_FORMAT``,
1182 ``DATETIME_FORMAT``, ``TIME_FORMAT`` and ``MONTH_DAY_FORMAT``.
1184 .. _cache docs: ../cache/
1185 .. _middleware docs: ../middleware/
1186 .. _session docs: ../sessions/
1187 .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
1188 .. _template documentation: ../templates_python/
1190 Creating your own settings
1191 ==========================
1193 There's nothing stopping you from creating your own settings, for your own
1194 Django apps. Just follow these conventions:
1196     * Setting names are in all uppercase.
1197     * For settings that are sequences, use tuples instead of lists. This is
1198       purely for performance.
1199     * Don't reinvent an already-existing setting.
1201 Using settings without setting DJANGO_SETTINGS_MODULE
1202 =====================================================
1204 In some cases, you might want to bypass the ``DJANGO_SETTINGS_MODULE``
1205 environment variable. For example, if you're using the template system by
1206 itself, you likely don't want to have to set up an environment variable
1207 pointing to a settings module.
1209 In these cases, you can configure Django's settings manually. Do this by
1210 calling ``django.conf.settings.configure()``.
1212 Example::
1214     from django.conf import settings
1216     settings.configure(DEBUG=True, TEMPLATE_DEBUG=True,
1217         TEMPLATE_DIRS=('/home/web-apps/myapp', '/home/web-apps/base'))
1219 Pass ``configure()`` as many keyword arguments as you'd like, with each keyword
1220 argument representing a setting and its value. Each argument name should be all
1221 uppercase, with the same name as the settings described above. If a particular
1222 setting is not passed to ``configure()`` and is needed at some later point,
1223 Django will use the default setting value.
1225 Configuring Django in this fashion is mostly necessary -- and, indeed,
1226 recommended -- when you're using a piece of the framework inside a larger
1227 application.
1229 Consequently, when configured via ``settings.configure()``, Django will not
1230 make any modifications to the process environment variables. (See the
1231 explanation of ``TIME_ZONE``, above, for why this would normally occur.) It's
1232 assumed that you're already in full control of your environment in these cases.
1234 Custom default settings
1235 -----------------------
1237 If you'd like default values to come from somewhere other than
1238 ``django.conf.global_settings``, you can pass in a module or class that
1239 provides the default settings as the ``default_settings`` argument (or as the
1240 first positional argument) in the call to ``configure()``.
1242 In this example, default settings are taken from ``myapp_defaults``, and the
1243 ``DEBUG`` setting is set to ``True``, regardless of its value in
1244 ``myapp_defaults``::
1246     from django.conf import settings
1247     from myapp import myapp_defaults
1249     settings.configure(default_settings=myapp_defaults, DEBUG=True)
1251 The following example, which uses ``myapp_defaults`` as a positional argument,
1252 is equivalent::
1254     settings.configure(myapp_defaults, DEBUG = True)
1256 Normally, you will not need to override the defaults in this fashion. The
1257 Django defaults are sufficiently tame that you can safely use them. Be aware
1258 that if you do pass in a new default module, it entirely *replaces* the Django
1259 defaults, so you must specify a value for every possible setting that might be
1260 used in that code you are importing. Check in
1261 ``django.conf.settings.global_settings`` for the full list.
1263 Either configure() or DJANGO_SETTINGS_MODULE is required
1264 --------------------------------------------------------
1266 If you're not setting the ``DJANGO_SETTINGS_MODULE`` environment variable, you
1267 *must* call ``configure()`` at some point before using any code that reads
1268 settings.
1270 If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``,
1271 Django will raise an ``ImportError`` exception the first time a setting
1272 is accessed.
1274 If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then*
1275 call ``configure()``, Django will raise a ``RuntimeError`` indicating
1276 that settings have already been configured.
1278 Also, it's an error to call ``configure()`` more than once, or to call
1279 ``configure()`` after any setting has been accessed.
1281 It boils down to this: Use exactly one of either ``configure()`` or
1282 ``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
1284 .. _@login_required: ../authentication/#the-login-required-decorator
1286 Error reporting via e-mail
1287 ==========================
1289 Server errors
1290 -------------
1292 When ``DEBUG`` is ``False``, Django will e-mail the users listed in the
1293 ``ADMIN`` setting whenever your code raises an unhandled exception and results
1294 in an internal server error (HTTP status code 500). This gives the
1295 administrators immediate notification of any errors.
1297 To disable this behavior, just remove all entries from the ``ADMINS`` setting.
1299 404 errors
1300 ----------
1302 When ``DEBUG`` is ``False``, ``SEND_BROKEN_LINK_EMAILS`` is ``True`` and your
1303 ``MIDDLEWARE_CLASSES`` setting includes ``CommonMiddleware``, Django will
1304 e-mail the users listed in the ``MANAGERS`` setting whenever your code raises
1305 a 404 and the request has a referer. (It doesn't bother to e-mail for 404s
1306 that don't have a referer.)
1308 You can tell Django to stop reporting particular 404s by tweaking the
1309 ``IGNORABLE_404_ENDS`` and ``IGNORABLE_404_STARTS`` settings. Both should be a
1310 tuple of strings. For example::
1312     IGNORABLE_404_ENDS = ('.php', '.cgi')
1313     IGNORABLE_404_STARTS = ('/phpmyadmin/',)
1315 In this example, a 404 to any URL ending with ``.php`` or ``.cgi`` will *not*
1316 be reported. Neither will any URL starting with ``/phpmyadmin/``.
1318 To disable this behavior, just remove all entries from the ``MANAGERS`` setting.