Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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