-
diff --git a/docs/faq/admin.txt b/docs/faq/admin.txt
a
|
b
|
|
10 | 10 | sent out by Django doesn't match the domain in your browser. Try these two |
11 | 11 | things: |
12 | 12 | |
13 | | * Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file |
| 13 | * Set the :setting:`SESSION_COOKIE_DOMAIN` setting in your admin config file |
14 | 14 | to match your domain. For example, if you're going to |
15 | 15 | "http://www.example.com/admin/" in your browser, in |
16 | 16 | "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.example.com'``. |
… |
… |
|
19 | 19 | don't have dots in them. If you're running the admin site on "localhost" |
20 | 20 | or another domain that doesn't have a dot in it, try going to |
21 | 21 | "localhost.localdomain" or "127.0.0.1". And set |
22 | | ``SESSION_COOKIE_DOMAIN`` accordingly. |
| 22 | :setting:`SESSION_COOKIE_DOMAIN` accordingly. |
23 | 23 | |
24 | 24 | I can't log in. When I enter a valid username and password, it brings up the login page again, with a "Please enter a correct username and password" error. |
25 | 25 | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
… |
… |
|
61 | 61 | My "list_filter" contains a ManyToManyField, but the filter doesn't display. |
62 | 62 | ---------------------------------------------------------------------------- |
63 | 63 | |
64 | | Django won't bother displaying the filter for a ``ManyToManyField`` if there |
| 64 | Django won't bother displaying the filter for a :class:`ManyToManyField` if there |
65 | 65 | are fewer than two related objects. |
66 | 66 | |
67 | 67 | For example, if your ``list_filter`` includes ``sites``, and there's only one |
-
diff --git a/docs/faq/models.txt b/docs/faq/models.txt
a
|
b
|
|
6 | 6 | How can I see the raw SQL queries Django is running? |
7 | 7 | ---------------------------------------------------- |
8 | 8 | |
9 | | Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do |
| 9 | Make sure your Django :setting:`DEBUG` setting is set to ``True``. Then, just do |
10 | 10 | this:: |
11 | 11 | |
12 | 12 | >>> from django.db import connection |
… |
… |
|
14 | 14 | [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls', |
15 | 15 | 'time': '0.002'}] |
16 | 16 | |
17 | | ``connection.queries`` is only available if ``DEBUG`` is ``True``. It's a list |
| 17 | :data:`connection.queries` is only available if :setting:`DEBUG` is ``True``. It's a list |
18 | 18 | of dictionaries in order of query execution. Each dictionary has the following:: |
19 | 19 | |
20 | 20 | ``sql`` -- The raw SQL statement |
21 | 21 | ``time`` -- How long the statement took to execute, in seconds. |
22 | 22 | |
23 | | ``connection.queries`` includes all SQL statements -- INSERTs, UPDATES, |
| 23 | :data:`connection.queries` includes all SQL statements -- INSERTs, UPDATES, |
24 | 24 | SELECTs, etc. Each time your app hits the database, the query will be recorded. |
25 | 25 | |
26 | 26 | Can I use Django with a pre-existing database? |
… |
… |
|
79 | 79 | |
80 | 80 | Django isn't known to leak memory. If you find your Django processes are |
81 | 81 | allocating more and more memory, with no sign of releasing it, check to make |
82 | | sure your ``DEBUG`` setting is set to ``False``. If ``DEBUG`` is ``True``, then |
| 82 | sure your :setting:`DEBUG` setting is set to ``False``. If ``DEBUG`` is ``True``, then |
83 | 83 | Django saves a copy of every SQL statement it has executed. |
84 | 84 | |
85 | | (The queries are saved in ``django.db.connection.queries``. See |
| 85 | (The queries are saved in :data:`django.db.connection.queries`. See |
86 | 86 | `How can I see the raw SQL queries Django is running?`_.) |
87 | 87 | |
88 | | To fix the problem, set ``DEBUG`` to ``False``. |
| 88 | To fix the problem, set :setting:`DEBUG` to ``False``. |
89 | 89 | |
90 | 90 | If you need to clear the query list manually at any point in your functions, |
91 | | just call ``reset_queries()``, like this:: |
| 91 | just call :func:`reset_queries`, like this:: |
92 | 92 | |
93 | 93 | from django import db |
94 | 94 | db.reset_queries() |
-
diff --git a/docs/howto/custom-file-storage.txt b/docs/howto/custom-file-storage.txt
a
|
b
|
|
61 | 61 | ``_save(name, content)`` |
62 | 62 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
63 | 63 | |
64 | | Called by ``Storage.save()``. The ``name`` will already have gone through |
65 | | ``get_valid_name()`` and ``get_available_name()``, and the ``content`` will be a |
66 | | ``File`` object itself. No return value is expected. |
| 64 | Called by :meth:`Storage.save`. The ``name`` will already have gone through |
| 65 | :meth:`get_valid_name` and :meth:`get_available_name`, and the ``content`` will be a |
| 66 | :class:`File` object itself. No return value is expected. |
67 | 67 | |
68 | 68 | ``get_valid_name(name)`` |
69 | 69 | ------------------------ |
… |
… |
|
73 | 73 | server, after having any path information removed. Override this to customize |
74 | 74 | how non-standard characters are converted to safe filenames. |
75 | 75 | |
76 | | The code provided on ``Storage`` retains only alpha-numeric characters, periods |
| 76 | The code provided on :class:`Storage` retains only alpha-numeric characters, periods |
77 | 77 | and underscores from the original filename, removing everything else. |
78 | 78 | |
79 | 79 | ``get_available_name(name)`` |
… |
… |
|
82 | 82 | Returns a filename that is available in the storage mechanism, possibly taking |
83 | 83 | the provided filename into account. The ``name`` argument passed to this method |
84 | 84 | will have already cleaned to a filename valid for the storage system, according |
85 | | to the ``get_valid_name()`` method described above. |
| 85 | to the :meth:`get_valid_name` method described above. |
86 | 86 | |
87 | | The code provided on ``Storage`` simply appends underscores to the filename |
| 87 | The code provided on :class:`Storage` simply appends underscores to the filename |
88 | 88 | until it finds one that's available in the destination directory. |
-
diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt
a
|
b
|
|
24 | 24 | views.py |
25 | 25 | |
26 | 26 | In this example, the ``explode`` command will be made available to any project |
27 | | that includes the ``blog`` application in ``settings.INSTALLED_APPS``. |
| 27 | that includes the ``blog`` application in |
| 28 | :setting:`settings.INSTALLED_APPS<INSTALLED_APPS>`. |
28 | 29 | |
29 | 30 | The ``explode.py`` module has only one requirement -- it must define a class |
30 | 31 | called ``Command`` that extends ``django.core.management.base.BaseCommand``. |
31 | 32 | |
32 | 33 | For more details on how to define your own commands, look at the code for the |
33 | | existing ``django-admin.py`` commands, in ``/django/core/management/commands``. |
34 | | No newline at end of file |
| 34 | existing ``django-admin.py`` commands, in ``/django/core/management/commands``. |
-
diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt
a
|
b
|
|
25 | 25 | |
26 | 26 | Alternatively, you may have a complex Python object that can somehow be |
27 | 27 | serialized to fit into a standard database column type. This is another case |
28 | | where a ``Field`` subclass will help you use your object with your models. |
| 28 | where a :class:`Field` subclass will help you use your object with your models. |
29 | 29 | |
30 | 30 | Our example object |
31 | 31 | ------------------ |
… |
… |
|
288 | 288 | If you aim to build a database-agnostic application, you should account for |
289 | 289 | differences in database column types. For example, the date/time column type |
290 | 290 | in PostgreSQL is called ``timestamp``, while the same column in MySQL is called |
291 | | ``datetime``. The simplest way to handle this in a ``db_type()`` method is to |
| 291 | ``datetime``. The simplest way to handle this in a :meth:`db_type` method is to |
292 | 292 | import the Django settings module and check the :setting:`DATABASE_ENGINE` setting. |
293 | 293 | For example:: |
294 | 294 | |
… |
… |
|
418 | 418 | .. method:: get_db_prep_save(self, value) |
419 | 419 | |
420 | 420 | Same as the above, but called when the Field value must be *saved* to the |
421 | | database. As the default implementation just calls ``get_db_prep_value``, you |
| 421 | database. As the default implementation just calls :meth:`get_db_prep_value`, you |
422 | 422 | shouldn't need to implement this method unless your custom field need a special |
423 | 423 | conversion when being saved that is not the same as the used for normal query |
424 | | parameters (which is implemented by ``get_db_prep_value``). |
| 424 | parameters (which is implemented by :meth:`get_db_prep_value`). |
425 | 425 | |
426 | 426 | Preprocessing values before saving |
427 | 427 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
… |
… |
|
453 | 453 | |
454 | 454 | Prepares the ``value`` for passing to the database when used in a lookup (a |
455 | 455 | ``WHERE`` constraint in SQL). The ``lookup_type`` will be one of the valid |
456 | | Django filter lookups: ``exact``, ``iexact``, ``contains``, ``icontains``, |
457 | | ``gt``, ``gte``, ``lt``, ``lte``, ``in``, ``startswith``, ``istartswith``, |
458 | | ``endswith``, ``iendswith``, ``range``, ``year``, ``month``, ``day``, |
459 | | ``isnull``, ``search``, ``regex``, and ``iregex``. |
| 456 | Django filter lookups: :lookup:`exact`, :lookup:`iexact`, :lookup:`contains`, :lookup:`icontains`, |
| 457 | :lookup:`gt`, :lookup:`gte`, :lookup:`lt`, :lookup:`lte`, :lookup:`in`, :lookup:`startswith`, :lookup:`istartswith`, |
| 458 | :lookup:`endswith`, :lookup:`iendswith`, :lookup:`range`, :lookup:`year`, :lookup:`month`, :lookup:`day`, |
| 459 | :lookup:`isnull`, :lookup:`search`, :lookup:`regex`, and :lookup:`iregex`. |
460 | 460 | |
461 | 461 | Your method must be prepared to handle all of these ``lookup_type`` values and |
462 | | should raise either a ``ValueError`` if the ``value`` is of the wrong sort (a |
| 462 | should raise either a :exc:`ValueError` if the ``value`` is of the wrong sort (a |
463 | 463 | list when you were expecting an object, for example) or a ``TypeError`` if |
464 | 464 | your field does not support that type of lookup. For many fields, you can get |
465 | 465 | by with handling the lookup types that need special handling for your field |
466 | 466 | and pass the rest of the :meth:`get_db_prep_lookup` method of the parent class. |
467 | 467 | |
468 | | If you needed to implement ``get_db_prep_save()``, you will usually need to |
469 | | implement ``get_db_prep_lookup()``. If you don't, ``get_db_prep_value`` will be |
470 | | called by the default implementation, to manage ``exact``, ``gt``, ``gte``, |
471 | | ``lt``, ``lte``, ``in`` and ``range`` lookups. |
| 468 | If you needed to implement :meth:`get_db_prep_save`, you will usually need to |
| 469 | implement :meth:`get_db_prep_lookup`. If you don't, :meth:`get_db_prep_value` will be |
| 470 | called by the default implementation, to manage :lookup:`exact`, :lookup:`gt`, :lookup:`gte`, |
| 471 | :lookup:`lt`, :lookup:`lte`, :lookup:`in` and :lookup:`range` lookups. |
472 | 472 | |
473 | 473 | You may also want to implement this method to limit the lookup types that could |
474 | 474 | be used with your custom field type. |
475 | 475 | |
476 | | Note that, for ``range`` and ``in`` lookups, ``get_db_prep_lookup`` will receive |
| 476 | Note that, for :lookup:`range` and :lookup:`in` lookups, :meth:`get_db_prep_lookup` will receive |
477 | 477 | a list of objects (presumably of the right type) and will need to convert them |
478 | 478 | to a list of things of the right type for passing to the database. Most of the |
479 | | time, you can reuse ``get_db_prep_value()``, or at least factor out some common |
| 479 | time, you can reuse :meth:`get_db_prep_value`, or at least factor out some common |
480 | 480 | pieces. |
481 | 481 | |
482 | | For example, the following code implements ``get_db_prep_lookup`` to limit the |
483 | | accepted lookup types to ``exact`` and ``in``:: |
| 482 | For example, the following code implements :meth:`get_db_prep_lookup` to limit the |
| 483 | accepted lookup types to :lookup:`exact` and ``in``:: |
484 | 484 | |
485 | 485 | class HandField(models.Field): |
486 | 486 | # ... |
… |
… |
|
608 | 608 | |
609 | 609 | In addition to the above methods, fields that deal with files have a few other |
610 | 610 | special requirements which must be taken into account. The majority of the |
611 | | mechanics provided by ``FileField``, such as controlling database storage and |
| 611 | mechanics provided by :class:`FileField`, such as controlling database storage and |
612 | 612 | retrieval, can remain unchanged, leaving subclasses to deal with the challenge |
613 | 613 | of supporting a particular type of file. |
614 | 614 | |
615 | | Django provides a ``File`` class, which is used as a proxy to the file's |
| 615 | Django provides a :class:`File` class, which is used as a proxy to the file's |
616 | 616 | contents and operations. This can be subclassed to customize how the file is |
617 | 617 | accessed, and what methods are available. It lives at |
618 | | ``django.db.models.fields.files``, and its default behavior is explained in the |
| 618 | :mod:`django.db.models.fields.files`, and its default behavior is explained in the |
619 | 619 | :ref:`file documentation <ref-files-file>`. |
620 | 620 | |
621 | | Once a subclass of ``File`` is created, the new ``FileField`` subclass must be |
622 | | told to use it. To do so, simply assign the new ``File`` subclass to the special |
623 | | ``attr_class`` attribute of the ``FileField`` subclass. |
| 621 | Once a subclass of :class:`File` is created, the new :class:`FileField` subclass must be |
| 622 | told to use it. To do so, simply assign the new :class:`File` subclass to the special |
| 623 | :attr:`attr_class` attribute of the ``FileField`` subclass. |
624 | 624 | |
625 | 625 | A few suggestions |
626 | 626 | ------------------ |
… |
… |
|
628 | 628 | In addition to the above details, there are a few guidelines which can greatly |
629 | 629 | improve the efficiency and readability of the field's code. |
630 | 630 | |
631 | | 1. The source for Django's own ``ImageField`` (in |
| 631 | 1. The source for Django's own :class:`ImageField` (in |
632 | 632 | ``django/db/models/fields/files.py``) is a great example of how to |
633 | 633 | subclass ``FileField`` to support a particular type of file, as it |
634 | 634 | incorporates all of the techniques described above. |
-
diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
a
|
b
|
|
57 | 57 | the given Python module name, not the name of the app. |
58 | 58 | |
59 | 59 | To be a valid tag library, the module must contain a module-level variable |
60 | | named ``register`` that is a ``template.Library`` instance, in which all the |
| 60 | named ``register`` that is a :class:`template.Library` instance, in which all the |
61 | 61 | tags and filters are registered. So, near the top of your module, put the |
62 | 62 | following:: |
63 | 63 | |
… |
… |
|
120 | 120 | return value.lower() |
121 | 121 | |
122 | 122 | This way, you'll be able to pass, say, an integer to this filter, and it |
123 | | won't cause an ``AttributeError`` (because integers don't have ``lower()`` |
| 123 | won't cause an :exc:`AttributeError` (because integers don't have ``lower()`` |
124 | 124 | methods). |
125 | 125 | |
126 | 126 | Registering custom filters |
127 | 127 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
128 | 128 | |
129 | 129 | Once you've written your filter definition, you need to register it with |
130 | | your ``Library`` instance, to make it available to Django's template language:: |
| 130 | your :class:`Library` instance, to make it available to Django's template language:: |
131 | 131 | |
132 | 132 | register.filter('cut', cut) |
133 | 133 | register.filter('lower', lower) |
134 | 134 | |
135 | | The ``Library.filter()`` method takes two arguments: |
| 135 | The :meth:`Library.filter` method takes two arguments: |
136 | 136 | |
137 | 137 | 1. The name of the filter -- a string. |
138 | 138 | 2. The compilation function -- a Python function (not the name of the |
139 | 139 | function as a string). |
140 | 140 | |
141 | | If you're using Python 2.4 or above, you can use ``register.filter()`` as a |
| 141 | If you're using Python 2.4 or above, you can use :func:`register.filter` as a |
142 | 142 | decorator instead:: |
143 | 143 | |
144 | 144 | @register.filter(name='cut') |
… |
… |
|
172 | 172 | They're commonly used for output that contains raw HTML that is intended |
173 | 173 | to be interpreted as-is on the client side. |
174 | 174 | |
175 | | Internally, these strings are of type ``SafeString`` or ``SafeUnicode``. |
176 | | They share a common base class of ``SafeData``, so you can test |
| 175 | Internally, these strings are of type :class:`SafeString` or :class:`SafeUnicode`. |
| 176 | They share a common base class of :class:`SafeData`, so you can test |
177 | 177 | for them using code like:: |
178 | 178 | |
179 | 179 | if isinstance(value, SafeData): |
… |
… |
|
184 | 184 | These strings are only escaped once, however, even if auto-escaping |
185 | 185 | applies. |
186 | 186 | |
187 | | Internally, these strings are of type ``EscapeString`` or |
188 | | ``EscapeUnicode``. Generally you don't have to worry about these; they |
| 187 | Internally, these strings are of type :class:`EscapeString` or |
| 188 | :class:`EscapeUnicode`. Generally you don't have to worry about these; they |
189 | 189 | exist for the implementation of the ``escape`` filter. |
190 | 190 | |
191 | 191 | Template filter code falls into one of two situations: |
… |
… |
|
209 | 209 | introduce any possibility of unsafe HTML." |
210 | 210 | |
211 | 211 | The reason ``is_safe`` is necessary is because there are plenty of |
212 | | normal string operations that will turn a ``SafeData`` object back into |
| 212 | normal string operations that will turn a :class:`SafeData` object back into |
213 | 213 | a normal ``str`` or ``unicode`` object and, rather than try to catch |
214 | 214 | them all, which would be very difficult, Django repairs the damage after |
215 | 215 | the filter has completed. |
… |
… |
|
289 | 289 | ``autoescape`` keyword argument mean that our function will know whether |
290 | 290 | automatic escaping is in effect when the filter is called. We use |
291 | 291 | ``autoescape`` to decide whether the input data needs to be passed |
292 | | through ``django.utils.html.conditional_escape`` or not. (In the latter |
| 292 | through :func:`django.utils.html.conditional_escape` or not. (In the latter |
293 | 293 | case, we just use the identity function as the "escape" function.) The |
294 | | ``conditional_escape()`` function is like ``escape()`` except it only |
295 | | escapes input that is **not** a ``SafeData`` instance. If a ``SafeData`` |
| 294 | :func:`conditional_escape` function is like :func:`escape` except it only |
| 295 | escapes input that is **not** a :class:`SafeData` instance. If a ``SafeData`` |
296 | 296 | instance is passed to ``conditional_escape()``, the data is returned |
297 | 297 | unchanged. |
298 | 298 | |
… |
… |
|
318 | 318 | how the compilation works and how the rendering works. |
319 | 319 | |
320 | 320 | When Django compiles a template, it splits the raw template text into |
321 | | ''nodes''. Each node is an instance of ``django.template.Node`` and has |
322 | | a ``render()`` method. A compiled template is, simply, a list of ``Node`` |
| 321 | ''nodes''. Each node is an instance of :class:`django.template.Node` and has |
| 322 | a ``render()`` method. A compiled template is, simply, a list of :class:`Node` |
323 | 323 | objects. When you call ``render()`` on a compiled template object, the template |
324 | 324 | calls ``render()`` on each ``Node`` in its node list, with the given context. |
325 | 325 | The results are all concatenated together to form the output of the template. |
… |
… |
|
346 | 346 | |
347 | 347 | .. _`strftime syntax`: http://docs.python.org/library/time.html#time.strftime |
348 | 348 | |
349 | | The parser for this function should grab the parameter and create a ``Node`` |
| 349 | The parser for this function should grab the parameter and create a :class:`Node` |
350 | 350 | object:: |
351 | 351 | |
352 | 352 | from django import template |
… |
… |
|
368 | 368 | * ``token.contents`` is a string of the raw contents of the tag. In our |
369 | 369 | example, it's ``'current_time "%Y-%m-%d %I:%M %p"'``. |
370 | 370 | |
371 | | * The ``token.split_contents()`` method separates the arguments on spaces |
| 371 | * The :meth:`token.split_contents` method separates the arguments on spaces |
372 | 372 | while keeping quoted strings together. The more straightforward |
373 | | ``token.contents.split()`` wouldn't be as robust, as it would naively |
| 373 | :func:`token.contents.split` wouldn't be as robust, as it would naively |
374 | 374 | split on *all* spaces, including those within quoted strings. It's a good |
375 | | idea to always use ``token.split_contents()``. |
| 375 | idea to always use :meth:`token.split_contents`. |
376 | 376 | |
377 | 377 | * This function is responsible for raising |
378 | | ``django.template.TemplateSyntaxError``, with helpful messages, for |
| 378 | :exc:`django.template.TemplateSyntaxError`, with helpful messages, for |
379 | 379 | any syntax error. |
380 | 380 | |
381 | | * The ``TemplateSyntaxError`` exceptions use the ``tag_name`` variable. |
| 381 | * The :exc:`TemplateSyntaxError` exceptions use the ``tag_name`` variable. |
382 | 382 | Don't hard-code the tag's name in your error messages, because that |
383 | 383 | couples the tag's name to your function. ``token.contents.split()[0]`` |
384 | 384 | will ''always'' be the name of your tag -- even when the tag has no |
… |
… |
|
397 | 397 | Writing the renderer |
398 | 398 | ~~~~~~~~~~~~~~~~~~~~ |
399 | 399 | |
400 | | The second step in writing custom tags is to define a ``Node`` subclass that |
401 | | has a ``render()`` method. |
| 400 | The second step in writing custom tags is to define a :class:`Node` subclass that |
| 401 | has a :meth:`render` method. |
402 | 402 | |
403 | 403 | Continuing the above example, we need to define ``CurrentTimeNode``:: |
404 | 404 | |
… |
… |
|
443 | 443 | |
444 | 444 | Also, if your template tag creates a new context for performing some |
445 | 445 | sub-rendering, set the auto-escape attribute to the current context's value. |
446 | | The ``__init__`` method for the ``Context`` class takes a parameter called |
| 446 | The ``__init__`` method for the :class:`Context` class takes a parameter called |
447 | 447 | ``autoescape`` that you can use for this purpose. For example:: |
448 | 448 | |
449 | 449 | def render(self, context): |
… |
… |
|
466 | 466 | Registering the tag |
467 | 467 | ~~~~~~~~~~~~~~~~~~~ |
468 | 468 | |
469 | | Finally, register the tag with your module's ``Library`` instance, as explained |
| 469 | Finally, register the tag with your module's :class:`Library` instance, as explained |
470 | 470 | in "Writing custom template filters" above. Example:: |
471 | 471 | |
472 | 472 | register.tag('current_time', do_current_time) |
… |
… |
|
496 | 496 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
497 | 497 | |
498 | 498 | Although you can pass any number of arguments to a template tag using |
499 | | ``token.split_contents()``, the arguments are all unpacked as |
| 499 | :meth:`token.split_contents`, the arguments are all unpacked as |
500 | 500 | string literals. A little more work is required in order to pass dynamic |
501 | 501 | content (a template variable) to a template tag as an argument. |
502 | 502 | |
503 | 503 | While the previous examples have formatted the current time into a string and |
504 | | returned the string, suppose you wanted to pass in a ``DateTimeField`` from an |
| 504 | returned the string, suppose you wanted to pass in a :class:`DateTimeField` from an |
505 | 505 | object and have the template tag format that date-time: |
506 | 506 | |
507 | 507 | .. code-block:: html+django |
508 | 508 | |
509 | 509 | <p>This post was last updated at {% format_time blog_entry.date_updated "%Y-%m-%d %I:%M %p" %}.</p> |
510 | 510 | |
511 | | Initially, ``token.split_contents()`` will return three values: |
| 511 | Initially, :meth:`token.split_contents` will return three values: |
512 | 512 | |
513 | 513 | 1. The tag name ``format_time``. |
514 | 514 | 2. The string "blog_entry.date_updated" (without the surrounding quotes). |
… |
… |
|
531 | 531 | |
532 | 532 | .. versionchanged:: 1.0 |
533 | 533 | Variable resolution has changed in the 1.0 release of Django. ``template.resolve_variable()`` |
534 | | has been deprecated in favor of a new ``template.Variable`` class. |
| 534 | has been deprecated in favor of a new :class:`template.Variable` class. |
535 | 535 | |
536 | 536 | You also have to change the renderer to retrieve the actual contents of the |
537 | 537 | ``date_updated`` property of the ``blog_entry`` object. This can be |
538 | | accomplished by using the ``Variable()`` class in ``django.template``. |
| 538 | accomplished by using the :class:`Variable` class in :mod:`django.template`. |
539 | 539 | |
540 | | To use the ``Variable`` class, simply instantiate it with the name of the |
| 540 | To use the :class:`Variable` class, simply instantiate it with the name of the |
541 | 541 | variable to be resolved, and then call ``variable.resolve(context)``. So, |
542 | 542 | for example:: |
543 | 543 | |
… |
… |
|
553 | 553 | except template.VariableDoesNotExist: |
554 | 554 | return '' |
555 | 555 | |
556 | | Variable resolution will throw a ``VariableDoesNotExist`` exception if it cannot |
| 556 | Variable resolution will throw a :exc:`VariableDoesNotExist` exception if it cannot |
557 | 557 | resolve the string passed to it in the current context of the page. |
558 | 558 | |
559 | 559 | Shortcut for simple tags |
… |
… |
|
567 | 567 | |
568 | 568 | To ease the creation of the types of tags, Django provides a helper function, |
569 | 569 | ``simple_tag``. This function, which is a method of |
570 | | ``django.template.Library``, takes a function that accepts any number of |
| 570 | :class:`django.template.Library`, takes a function that accepts any number of |
571 | 571 | arguments, wraps it in a ``render`` function and the other necessary bits |
572 | 572 | mentioned above and registers it with the template system. |
573 | 573 | |
… |
… |
|
652 | 652 | </ul> |
653 | 653 | |
654 | 654 | Now, create and register the inclusion tag by calling the ``inclusion_tag()`` |
655 | | method on a ``Library`` object. Following our example, if the above template is |
| 655 | method on a :class:`Library` object. Following our example, if the above template is |
656 | 656 | in a file called ``results.html`` in a directory that's searched by the template |
657 | 657 | loader, we'd register the tag like this:: |
658 | 658 | |
… |
… |
|
690 | 690 | |
691 | 691 | (Note that the first parameter to the function *must* be called ``context``.) |
692 | 692 | |
693 | | In that ``register.inclusion_tag()`` line, we specified ``takes_context=True`` |
| 693 | In that :func:`register.inclusion_tag` line, we specified ``takes_context=True`` |
694 | 694 | and the name of the template. Here's what the template ``link.html`` might look |
695 | 695 | like: |
696 | 696 | |
… |
… |
|
802 | 802 | return '' |
803 | 803 | |
804 | 804 | ``parser.parse()`` takes a tuple of names of block tags ''to parse until''. It |
805 | | returns an instance of ``django.template.NodeList``, which is a list of |
806 | | all ``Node`` objects that the parser encountered ''before'' it encountered |
| 805 | returns an instance of :class:`django.template.NodeList`, which is a list of |
| 806 | all :class:`Node` objects that the parser encountered ''before'' it encountered |
807 | 807 | any of the tags named in the tuple. |
808 | 808 | |
809 | 809 | In ``"nodelist = parser.parse(('endcomment',))"`` in the above example, |
… |
… |
|
813 | 813 | |
814 | 814 | After ``parser.parse()`` is called, the parser hasn't yet "consumed" the |
815 | 815 | ``{% endcomment %}`` tag, so the code needs to explicitly call |
816 | | ``parser.delete_first_token()``. |
| 816 | :func:`parser.delete_first_token`. |
817 | 817 | |
818 | 818 | ``CommentNode.render()`` simply returns an empty string. Anything between |
819 | 819 | ``{% comment %}`` and ``{% endcomment %}`` is ignored. |
-
diff --git a/docs/howto/deployment/fastcgi.txt b/docs/howto/deployment/fastcgi.txt
a
|
b
|
|
371 | 371 | |
372 | 372 | In the cases where Django cannot work out the prefix correctly and where you |
373 | 373 | want the original value to be used in URLs, you can set the |
374 | | ``FORCE_SCRIPT_NAME`` setting in your main ``settings`` file. This sets the |
| 374 | :setting:`FORCE_SCRIPT_NAME` setting in your main ``settings`` file. This sets the |
375 | 375 | script name uniformly for every URL served via that settings file. Thus you'll |
376 | 376 | need to use different settings files if you want different sets of URLs to |
377 | 377 | have different script names in this case, but that is a rare situation. |
-
diff --git a/docs/howto/static-files.txt b/docs/howto/static-files.txt
a
|
b
|
|
148 | 148 | |
149 | 149 | This code is straightforward. It imports the settings and checks the value of |
150 | 150 | the :setting:`DEBUG` setting. If it evaluates to ``True``, then ``site_media`` |
151 | | will be associated with the ``django.views.static.serve`` view. If not, then the |
| 151 | will be associated with the :func:`django.views.static.serve` view. If not, then the |
152 | 152 | view won't be made available. |
153 | 153 | |
154 | 154 | Of course, the catch here is that you'll have to remember to set ``DEBUG=False`` |
-
diff --git a/docs/internals/contributing.txt b/docs/internals/contributing.txt
a
|
b
|
|
752 | 752 | ./runtests.py --settings=path.to.django.settings |
753 | 753 | |
754 | 754 | Yes, the unit tests need a settings module, but only for database connection |
755 | | info, with the ``DATABASE_ENGINE`` setting. |
| 755 | info, with the :setting:`DATABASE_ENGINE` setting. |
756 | 756 | |
757 | 757 | If you're using the ``sqlite3`` database backend, no further settings are |
758 | 758 | needed. A temporary database will be created in memory when running the tests. |
… |
… |
|
771 | 771 | |
772 | 772 | You will also need to ensure that your database uses UTF-8 as the default |
773 | 773 | character set. If your database server doesn't use UTF-8 as a default charset, |
774 | | you will need to include a value for ``TEST_DATABASE_CHARSET`` in your settings |
| 774 | you will need to include a value for :setting:`TEST_DATABASE_CHARSET` in your settings |
775 | 775 | file. |
776 | 776 | |
777 | 777 | If you want to run the full suite of tests, you'll need to install a number of |
-
diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt
a
|
b
|
|
158 | 158 | |
159 | 159 | * :setting:`DATABASE_NAME` -- The name of your database. If you're using |
160 | 160 | SQLite, the database will be a file on your computer; in that case, |
161 | | ``DATABASE_NAME`` should be the full absolute path, including filename, of |
| 161 | :setting:`DATABASE_NAME` should be the full absolute path, including filename, of |
162 | 162 | that file. If the file doesn't exist, it will automatically be created |
163 | 163 | when you synchronize the database for the first time (see below). |
164 | 164 | |
-
diff --git a/docs/misc/api-stability.txt b/docs/misc/api-stability.txt
a
|
b
|
|
96 | 96 | ``django.utils`` |
97 | 97 | ---------------- |
98 | 98 | |
99 | | Most of the modules in ``django.utils`` are designed for internal use. Only the following parts of ``django.utils`` can be considered stable: |
| 99 | Most of the modules in :mod:`django.utils` are designed for internal use. Only the following parts of :mod:`django.utils` can be considered stable: |
100 | 100 | |
101 | | - ``django.utils.cache`` |
102 | | - ``django.utils.datastructures.SortedDict`` -- only this single class; the |
| 101 | - :mod:`django.utils.cache` |
| 102 | - :class:`django.utils.datastructures.SortedDict` -- only this single class; the |
103 | 103 | rest of the module is for internal use. |
104 | | - ``django.utils.encoding`` |
105 | | - ``django.utils.feedgenerator`` |
106 | | - ``django.utils.http`` |
107 | | - ``django.utils.safestring`` |
108 | | - ``django.utils.translation`` |
109 | | - ``django.utils.tzinfo`` |
| 104 | - :mod:`django.utils.encoding` |
| 105 | - :mod:`django.utils.feedgenerator` |
| 106 | - :mod:`django.utils.http` |
| 107 | - :mod:`django.utils.safestring` |
| 108 | - :mod:`django.utils.translation` |
| 109 | - :mod:`django.utils.tzinfo` |
110 | 110 | |
111 | 111 | Exceptions |
112 | 112 | ========== |
… |
… |
|
134 | 134 | ``django.contrib.flatpages``, we'll make sure you can still use the Django 1.4 |
135 | 135 | version alongside Django 1.5. This will continue to allow for easy upgrades. |
136 | 136 | |
137 | | Historically, apps in ``django.contrib`` have been more stable than the core, so |
| 137 | Historically, apps in :mod:`django.contrib` have been more stable than the core, so |
138 | 138 | in practice we probably won't have to ever make this exception. However, it's |
139 | | worth noting if you're building apps that depend on ``django.contrib``. |
| 139 | worth noting if you're building apps that depend on :mod:`django.contrib`. |
140 | 140 | |
141 | 141 | APIs marked as internal |
142 | 142 | ----------------------- |
-
diff --git a/docs/misc/design-philosophies.txt b/docs/misc/design-philosophies.txt
a
|
b
|
|
130 | 130 | This is why developers need to call ``save()`` explicitly, rather than the |
131 | 131 | framework saving things behind the scenes silently. |
132 | 132 | |
133 | | This is also why the ``select_related()`` ``QuerySet`` method exists. It's an |
| 133 | This is also why the ``select_related()`` :class:`QuerySet` method exists. It's an |
134 | 134 | optional performance booster for the common case of selecting "every related |
135 | 135 | object." |
136 | 136 | |
-
diff --git a/docs/ref/contrib/admin.txt b/docs/ref/contrib/admin.txt
a
|
b
|
|
25 | 25 | |
26 | 26 | There are five steps in activating the Django admin site: |
27 | 27 | |
28 | | 1. Add ``django.contrib.admin`` to your ``INSTALLED_APPS`` setting. |
| 28 | 1. Add ``django.contrib.admin`` to your :setting:`INSTALLED_APPS` setting. |
29 | 29 | |
30 | 30 | 2. Determine which of your application's models should be editable in the |
31 | 31 | admin interface. |
… |
… |
|
112 | 112 | dictionary of information about the fieldset, including a list of fields to be |
113 | 113 | displayed in it. |
114 | 114 | |
115 | | A full example, taken from the ``django.contrib.flatpages.FlatPage`` model:: |
| 115 | A full example, taken from the :class:`django.contrib.flatpages.FlatPage` model:: |
116 | 116 | |
117 | 117 | class FlatPageAdmin(admin.ModelAdmin): |
118 | 118 | fieldsets = ( |
… |
… |
|
184 | 184 | Use this option as an alternative to ``fieldsets`` if the layout does not |
185 | 185 | matter and if you want to only show a subset of the available fields in the |
186 | 186 | form. For example, you could define a simpler version of the admin form for |
187 | | the ``django.contrib.flatpages.FlatPage`` model as follows:: |
| 187 | the :class:`django.contrib.flatpages.FlatPage` model as follows:: |
188 | 188 | |
189 | 189 | class FlatPageAdmin(admin.ModelAdmin): |
190 | 190 | fields = ('url', 'title', 'content') |
… |
… |
|
411 | 411 | field should be either a ``BooleanField``, ``CharField``, ``DateField``, |
412 | 412 | ``DateTimeField``, ``IntegerField`` or ``ForeignKey``. |
413 | 413 | |
414 | | This example, taken from the ``django.contrib.auth.models.User`` model, shows |
| 414 | This example, taken from the :class:`django.contrib.auth.models.User` model, shows |
415 | 415 | how both ``list_display`` and ``list_filter`` work:: |
416 | 416 | |
417 | 417 | class UserAdmin(admin.ModelAdmin): |
… |
… |
|
495 | 495 | radio_fields = {"group": admin.VERTICAL} |
496 | 496 | |
497 | 497 | You have the choice of using ``HORIZONTAL`` or ``VERTICAL`` from the |
498 | | ``django.contrib.admin`` module. |
| 498 | :mod:`django.contrib.admin` module. |
499 | 499 | |
500 | 500 | Don't include a field in ``radio_fields`` unless it's a ``ForeignKey`` or has |
501 | 501 | ``choices`` set. |
… |
… |
|
646 | 646 | } |
647 | 647 | js = ("my_code.js",) |
648 | 648 | |
649 | | Keep in mind that this will be prepended with ``MEDIA_URL``. The same rules |
| 649 | Keep in mind that this will be prepended with :setting:`MEDIA_URL`. The same rules |
650 | 650 | apply as :ref:`regular media definitions on forms <topics-forms-media>`. |
651 | 651 | |
652 | 652 | Adding custom validation to the admin |
… |
… |
|
871 | 871 | |
872 | 872 | If you want to allow editing and creating ``Image`` instance on the ``Product`` |
873 | 873 | add/change views you can simply use ``GenericInlineModelAdmin`` provided by |
874 | | ``django.contrib.contenttypes.generic``. In your ``admin.py`` for this |
| 874 | :mod:`django.contrib.contenttypes.generic`. In your ``admin.py`` for this |
875 | 875 | example app:: |
876 | 876 | |
877 | 877 | from django.contrib import admin |
… |
… |
|
889 | 889 | |
890 | 890 | admin.site.register(Product, ProductAdmin) |
891 | 891 | |
892 | | ``django.contrib.contenttypes.generic`` provides both a ``GenericTabularInline`` |
| 892 | :mod:`django.contrib.contenttypes.generic` provides both a ``GenericTabularInline`` |
893 | 893 | and ``GenericStackedInline`` and behave just like any other inline. See the |
894 | 894 | :ref:`contenttypes documentation <ref-contrib-contenttypes>` for more specific |
895 | 895 | information. |
… |
… |
|
909 | 909 | |
910 | 910 | In order to override one or more of them, first create an ``admin`` directory in |
911 | 911 | your project's ``templates`` directory. This can be any of the directories you |
912 | | specified in ``TEMPLATE_DIRS``. |
| 912 | specified in :setting:`TEMPLATE_DIRS`. |
913 | 913 | |
914 | 914 | Within this ``admin`` directory, create sub-directories named after your app. |
915 | 915 | Within these app subdirectories create sub-directories named after your models. |
… |
… |
|
998 | 998 | ===================== |
999 | 999 | |
1000 | 1000 | A Django administrative site is represented by an instance of |
1001 | | ``django.contrib.admin.sites.AdminSite``; by default, an instance of |
| 1001 | :class:`django.contrib.admin.sites.AdminSite`; by default, an instance of |
1002 | 1002 | this class is created as ``django.contrib.admin.site`` and you can |
1003 | 1003 | register your models and ``ModelAdmin`` instances with it. |
1004 | 1004 | |
… |
… |
|
1031 | 1031 | ) |
1032 | 1032 | |
1033 | 1033 | Above we used ``admin.autodiscover()`` to automatically load the |
1034 | | ``INSTALLED_APPS`` admin.py modules. |
| 1034 | :setting:`INSTALLED_APPS` admin.py modules. |
1035 | 1035 | |
1036 | 1036 | In this example, we register the ``AdminSite`` instance |
1037 | 1037 | ``myproject.admin.admin_site`` at the URL ``/myadmin/`` :: |
-
diff --git a/docs/ref/contrib/comments/settings.txt b/docs/ref/contrib/comments/settings.txt
a
|
b
|
|
29 | 29 | COMMENTS_APP |
30 | 30 | ------------ |
31 | 31 | |
32 | | The app (i.e. entry in ``INSTALLED_APPS``) responsible for all "business logic." |
| 32 | The app (i.e. entry in :setting:`INSTALLED_APPS`) responsible for all "business logic." |
33 | 33 | You can change this to provide custom comment models and forms, though this is |
34 | 34 | currently undocumented. |
-
diff --git a/docs/ref/contrib/index.txt b/docs/ref/contrib/index.txt
a
|
b
|
|
16 | 16 | |
17 | 17 | For most of these add-ons -- specifically, the add-ons that include either |
18 | 18 | models or template tags -- you'll need to add the package name (e.g., |
19 | | ``'django.contrib.admin'``) to your ``INSTALLED_APPS`` setting and re-run |
| 19 | ``'django.contrib.admin'``) to your :setting:`INSTALLED_APPS` setting and re-run |
20 | 20 | ``manage.py syncdb``. |
21 | 21 | |
22 | 22 | .. _"batteries included" philosophy: http://docs.python.org/tut/node12.html#batteries-included |
… |
… |
|
121 | 121 | =========== |
122 | 122 | |
123 | 123 | A collection of various Django snippets that are useful only for a particular |
124 | | country or culture. For example, ``django.contrib.localflavor.us.forms`` |
| 124 | country or culture. For example, :mod:`django.contrib.localflavor.us.forms` |
125 | 125 | contains a ``USZipCodeField`` that you can use to validate U.S. zip codes. |
126 | 126 | |
127 | 127 | See the :ref:`localflavor documentation <ref-contrib-localflavor>`. |
-
diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt
a
|
b
|
|
64 | 64 | * `United Kingdom`_ |
65 | 65 | * `United States of America`_ |
66 | 66 | |
67 | | The ``django.contrib.localflavor`` package also includes a ``generic`` subpackage, |
| 67 | The :mod:`django.contrib.localflavor` package also includes a ``generic`` subpackage, |
68 | 68 | containing useful code that is not specific to one particular country or |
69 | 69 | culture. Currently, it defines date and datetime input fields based on those |
70 | 70 | from :ref:`forms <topics-forms-index>`, but with non-US default formats. |
-
diff --git a/docs/ref/contrib/webdesign.txt b/docs/ref/contrib/webdesign.txt
a
|
b
|
|
8 | 8 | :synopsis: Helpers and utilities targeted primarily at Web *designers* |
9 | 9 | rather than Web *developers*. |
10 | 10 | |
11 | | The ``django.contrib.webdesign`` package, part of the |
| 11 | The :mod:`django.contrib.webdesign` package, part of the |
12 | 12 | :ref:`"django.contrib" add-ons <ref-contrib-index>`, provides various Django |
13 | 13 | helpers that are particularly useful to Web *designers* (as opposed to |
14 | 14 | developers). |
-
diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
a
|
b
|
|
173 | 173 | :setting:`DATABASE_PORT` |
174 | 174 | 3. MySQL option files. |
175 | 175 | |
176 | | In other words, if you set the name of the database in ``DATABASE_OPTIONS``, |
177 | | this will take precedence over ``DATABASE_NAME``, which would override |
| 176 | In other words, if you set the name of the database in :setting:`DATABASE_OPTIONS`, |
| 177 | this will take precedence over :setting:`DATABASE_NAME`, which would override |
178 | 178 | anything in a `MySQL option file`_. |
179 | 179 | |
180 | 180 | Here's a sample configuration which uses a MySQL option file:: |
-
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
a
|
b
|
|
59 | 59 | --------- |
60 | 60 | |
61 | 61 | Many subcommands take a list of "app names." An "app name" is the basename of |
62 | | the package containing your models. For example, if your ``INSTALLED_APPS`` |
| 62 | the package containing your models. For example, if your :setting:`INSTALLED_APPS` |
63 | 63 | contains the string ``'mysite.blog'``, the app name is ``blog``. |
64 | 64 | |
65 | 65 | Determining the version |
… |
… |
|
148 | 148 | it when running interactively. |
149 | 149 | |
150 | 150 | This command is only available if Django's :ref:`authentication system |
151 | | <topics-auth>` (``django.contrib.auth``) is installed. |
| 151 | <topics-auth>` (:mod:`django.contrib.auth`) is installed. |
152 | 152 | |
153 | 153 | dbshell |
154 | 154 | ------- |
… |
… |
|
156 | 156 | .. django-admin:: dbshell |
157 | 157 | |
158 | 158 | Runs the command-line client for the database engine specified in your |
159 | | ``DATABASE_ENGINE`` setting, with the connection parameters specified in your |
160 | | ``DATABASE_USER``, ``DATABASE_PASSWORD``, etc., settings. |
| 159 | :setting:`DATABASE_ENGINE` setting, with the connection parameters specified in your |
| 160 | :setting:`DATABASE_USER`, :setting:`DATABASE_PASSWORD`, etc., settings. |
161 | 161 | |
162 | 162 | * For PostgreSQL, this runs the ``psql`` command-line client. |
163 | 163 | * For MySQL, this runs the ``mysql`` command-line client. |
… |
… |
|
177 | 177 | settings. |
178 | 178 | |
179 | 179 | Settings that don't appear in the defaults are followed by ``"###"``. For |
180 | | example, the default settings don't define ``ROOT_URLCONF``, so |
| 180 | example, the default settings don't define :setting:`ROOT_URLCONF`, so |
181 | 181 | ``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``. |
182 | 182 | |
183 | 183 | Note that Django's default settings live in ``django/conf/global_settings.py``, |
… |
… |
|
248 | 248 | --------- |
249 | 249 | |
250 | 250 | Introspects the database tables in the database pointed-to by the |
251 | | ``DATABASE_NAME`` setting and outputs a Django model module (a ``models.py`` |
| 251 | :setting:`DATABASE_NAME` setting and outputs a Django model module (a ``models.py`` |
252 | 252 | file) to standard output. |
253 | 253 | |
254 | 254 | Use this if you have a legacy database with which you'd like to use Django. |
… |
… |
|
300 | 300 | Django will search in three locations for fixtures: |
301 | 301 | |
302 | 302 | 1. In the ``fixtures`` directory of every installed application |
303 | | 2. In any directory named in the ``FIXTURE_DIRS`` setting |
| 303 | 2. In any directory named in the :setting:`FIXTURE_DIRS` setting |
304 | 304 | 3. In the literal path named by the fixture |
305 | 305 | |
306 | 306 | Django will load any and all fixtures it finds in these locations that match |
… |
… |
|
331 | 331 | |
332 | 332 | would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed |
333 | 333 | application, ``<dirname>/foo/bar/mydata.json`` for each directory in |
334 | | ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``. |
| 334 | :setting:`FIXTURE_DIRS`, and the literal path ``foo/bar/mydata.json``. |
335 | 335 | |
336 | 336 | Note that the order in which fixture files are processed is undefined. However, |
337 | 337 | all fixture data is installed as a single transaction, so data in |
… |
… |
|
525 | 525 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
526 | 526 | |
527 | 527 | By default, the development server doesn't serve any static files for your site |
528 | | (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If |
| 528 | (such as CSS files, images, things under :setting:`MEDIA_URL` and so forth). If |
529 | 529 | you want to configure Django to serve static media, read :ref:`howto-static-files`. |
530 | 530 | |
531 | 531 | Turning off auto-reload |
… |
… |
|
629 | 629 | syncdb |
630 | 630 | ------ |
631 | 631 | |
632 | | Creates the database tables for all apps in ``INSTALLED_APPS`` whose tables |
| 632 | Creates the database tables for all apps in :setting:`INSTALLED_APPS` whose tables |
633 | 633 | have not already been created. |
634 | 634 | |
635 | 635 | Use this command when you've added new applications to your project and want to |
636 | 636 | install them in the database. This includes any apps shipped with Django that |
637 | | might be in ``INSTALLED_APPS`` by default. When you start a new project, run |
| 637 | might be in :setting:`INSTALLED_APPS` by default. When you start a new project, run |
638 | 638 | this command to install the default apps. |
639 | 639 | |
640 | 640 | .. admonition:: Syncdb will not alter existing tables |
… |
… |
|
650 | 650 | to match, use the ``sql`` command to display the new SQL structure and |
651 | 651 | compare that to your existing table schema to work out the changes. |
652 | 652 | |
653 | | If you're installing the ``django.contrib.auth`` application, ``syncdb`` will |
| 653 | If you're installing the :mod:`django.contrib.auth` application, ``syncdb`` will |
654 | 654 | give you the option of creating a superuser immediately. |
655 | 655 | |
656 | 656 | ``syncdb`` will also search for and install any fixture named ``initial_data`` |
… |
… |
|
741 | 741 | validate |
742 | 742 | -------- |
743 | 743 | |
744 | | Validates all installed models (according to the ``INSTALLED_APPS`` setting) |
| 744 | Validates all installed models (according to the :setting:`INSTALLED_APPS` setting) |
745 | 745 | and prints validation errors to standard output. |
746 | 746 | |
747 | 747 | Default options |
-
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt
a
|
b
|
|
132 | 132 | Accessing "clean" data |
133 | 133 | ---------------------- |
134 | 134 | |
135 | | Each ``Field`` in a ``Form`` class is responsible not only for validating data, |
| 135 | Each :class:`Field` in a :class:`Form` class is responsible not only for validating data, |
136 | 136 | but also for "cleaning" it -- normalizing it to a consistent format. This is a |
137 | 137 | nice feature, because it allows data for a particular field to be input in |
138 | 138 | a variety of ways, always resulting in consistent output. |
139 | 139 | |
140 | | For example, ``DateField`` normalizes input into a Python ``datetime.date`` |
| 140 | For example, :class:`DateField` normalizes input into a Python ``datetime.date`` |
141 | 141 | object. Regardless of whether you pass it a string in the format |
142 | 142 | ``'1994-07-15'``, a ``datetime.date`` object or a number of other formats, |
143 | 143 | ``DateField`` will always normalize it to a ``datetime.date`` object as long as |
144 | 144 | it's valid. |
145 | 145 | |
146 | | Once you've created a ``Form`` instance with a set of data and validated it, |
147 | | you can access the clean data via the ``cleaned_data`` attribute of the ``Form`` |
| 146 | Once you've created a :class:`Form` instance with a set of data and validated it, |
| 147 | you can access the clean data via the :attr:`cleaned_data` attribute of the ``Form`` |
148 | 148 | object:: |
149 | 149 | |
150 | 150 | >>> data = {'subject': 'hello', |
… |
… |
|
158 | 158 | {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} |
159 | 159 | |
160 | 160 | .. versionchanged:: 1.0 |
161 | | The ``cleaned_data`` attribute was called ``clean_data`` in earlier releases. |
| 161 | The :attr:`cleaned_data` attribute was called ``clean_data`` in earlier releases. |
162 | 162 | |
163 | | Note that any text-based field -- such as ``CharField`` or ``EmailField`` -- |
| 163 | Note that any text-based field -- such as :class:`CharField` or :class:`EmailField` -- |
164 | 164 | always cleans the input into a Unicode string. We'll cover the encoding |
165 | 165 | implications later in this document. |
166 | 166 | |
167 | | If your data does *not* validate, your ``Form`` instance will not have a |
168 | | ``cleaned_data`` attribute:: |
| 167 | If your data does *not* validate, your :class:`Form` instance will not have a |
| 168 | :attr:`cleaned_data` attribute:: |
169 | 169 | |
170 | 170 | >>> data = {'subject': '', |
171 | 171 | ... 'message': 'Hi there', |
… |
… |
|
179 | 179 | ... |
180 | 180 | AttributeError: 'ContactForm' object has no attribute 'cleaned_data' |
181 | 181 | |
182 | | ``cleaned_data`` will always *only* contain a key for fields defined in the |
183 | | ``Form``, even if you pass extra data when you define the ``Form``. In this |
| 182 | :attr:`cleaned_data` will always *only* contain a key for fields defined in the |
| 183 | :class:`Form`, even if you pass extra data when you define the :class:`Form`. In this |
184 | 184 | example, we pass a bunch of extra fields to the ``ContactForm`` constructor, |
185 | | but ``cleaned_data`` contains only the form's fields:: |
| 185 | but :attr:`cleaned_data` contains only the form's fields:: |
186 | 186 | |
187 | 187 | >>> data = {'subject': 'hello', |
188 | 188 | ... 'message': 'Hi there', |
… |
… |
|
197 | 197 | >>> f.cleaned_data # Doesn't contain extra_field_1, etc. |
198 | 198 | {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} |
199 | 199 | |
200 | | ``cleaned_data`` will include a key and value for *all* fields defined in the |
201 | | ``Form``, even if the data didn't include a value for fields that are not |
| 200 | :attr:`cleaned_data` will include a key and value for *all* fields defined in the |
| 201 | :class:`Form`, even if the data didn't include a value for fields that are not |
202 | 202 | required. In this example, the data dictionary doesn't include a value for the |
203 | | ``nick_name`` field, but ``cleaned_data`` includes it, with an empty value:: |
| 203 | ``nick_name`` field, but :attr:`cleaned_data` includes it, with an empty value:: |
204 | 204 | |
205 | 205 | >>> class OptionalPersonForm(Form): |
206 | 206 | ... first_name = CharField() |
… |
… |
|
213 | 213 | >>> f.cleaned_data |
214 | 214 | {'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} |
215 | 215 | |
216 | | In this above example, the ``cleaned_data`` value for ``nick_name`` is set to an |
217 | | empty string, because ``nick_name`` is ``CharField``, and ``CharField``\s treat |
| 216 | In this above example, the :attr:`cleaned_data` value for ``nick_name`` is set to an |
| 217 | empty string, because ``nick_name`` is :class:`CharField`, and :class:`CharField`\s treat |
218 | 218 | empty values as an empty string. Each field type knows what its "blank" value |
219 | | is -- e.g., for ``DateField``, it's ``None`` instead of the empty string. For |
| 219 | is -- e.g., for :class:`DateField`, it's ``None`` instead of the empty string. For |
220 | 220 | full details on each field's behavior in this case, see the "Empty value" note |
221 | | for each field in the "Built-in ``Field`` classes" section below. |
| 221 | for each field in the "Built-in :class:`Field` classes" section below. |
222 | 222 | |
223 | 223 | You can write code to perform validation for particular form fields (based on |
224 | 224 | their name) or for the form as a whole (considering combinations of various |
… |
… |
|
227 | 227 | Outputting forms as HTML |
228 | 228 | ------------------------ |
229 | 229 | |
230 | | The second task of a ``Form`` object is to render itself as HTML. To do so, |
| 230 | The second task of a :class:`Form` object is to render itself as HTML. To do so, |
231 | 231 | simply ``print`` it:: |
232 | 232 | |
233 | 233 | >>> f = ContactForm() |
… |
… |
|
261 | 261 | ``</table>`` tags, nor does it include the ``<form>`` and ``</form>`` |
262 | 262 | tags or an ``<input type="submit">`` tag. It's your job to do that. |
263 | 263 | |
264 | | * Each field type has a default HTML representation. ``CharField`` and |
265 | | ``EmailField`` are represented by an ``<input type="text">``. |
266 | | ``BooleanField`` is represented by an ``<input type="checkbox">``. Note |
| 264 | * Each field type has a default HTML representation. :class:`CharField` and |
| 265 | :class:`EmailField` are represented by an ``<input type="text">``. |
| 266 | :class:`BooleanField` is represented by an ``<input type="checkbox">``. Note |
267 | 267 | these are merely sensible defaults; you can specify which HTML to use for |
268 | 268 | a given field by using widgets, which we'll explain shortly. |
269 | 269 | |
… |
… |
|
288 | 288 | ``as_p()`` |
289 | 289 | ~~~~~~~~~~ |
290 | 290 | |
291 | | ``Form.as_p()`` renders the form as a series of ``<p>`` tags, with each ``<p>`` |
| 291 | :meth:`Form.as_p` renders the form as a series of ``<p>`` tags, with each ``<p>`` |
292 | 292 | containing one field:: |
293 | 293 | |
294 | 294 | >>> f = ContactForm() |
… |
… |
|
303 | 303 | ``as_ul()`` |
304 | 304 | ~~~~~~~~~~~ |
305 | 305 | |
306 | | ``Form.as_ul()`` renders the form as a series of ``<li>`` tags, with each |
| 306 | :meth:`Form.as_ul` renders the form as a series of ``<li>`` tags, with each |
307 | 307 | ``<li>`` containing one field. It does *not* include the ``<ul>`` or ``</ul>``, |
308 | 308 | so that you can specify any HTML attributes on the ``<ul>`` for flexibility:: |
309 | 309 | |
… |
… |
|
319 | 319 | ``as_table()`` |
320 | 320 | ~~~~~~~~~~~~~~ |
321 | 321 | |
322 | | Finally, ``Form.as_table()`` outputs the form as an HTML ``<table>``. This is |
| 322 | Finally, :meth:`Form.as_table` outputs the form as an HTML ``<table>``. This is |
323 | 323 | exactly the same as ``print``. In fact, when you ``print`` a form object, it |
324 | | calls its ``as_table()`` method behind the scenes:: |
| 324 | calls its :meth:`as_table` method behind the scenes:: |
325 | 325 | |
326 | 326 | >>> f = ContactForm() |
327 | 327 | >>> f.as_table() |
… |
… |
|
347 | 347 | This behavior is configurable, though, if you want to change the ``id`` |
348 | 348 | convention or remove HTML ``id`` attributes and ``<label>`` tags entirely. |
349 | 349 | |
350 | | Use the ``auto_id`` argument to the ``Form`` constructor to control the label |
| 350 | Use the ``auto_id`` argument to the :class:`Form` constructor to control the label |
351 | 351 | and ``id`` behavior. This argument must be ``True``, ``False`` or a string. |
352 | 352 | |
353 | 353 | If ``auto_id`` is ``False``, then the form output will not include ``<label>`` |
… |
… |
|
442 | 442 | Notes on field ordering |
443 | 443 | ~~~~~~~~~~~~~~~~~~~~~~~ |
444 | 444 | |
445 | | In the ``as_p()``, ``as_ul()`` and ``as_table()`` shortcuts, the fields are |
| 445 | In the :meth:`as_p`, :meth:`as_ul` and :meth:`as_table` shortcuts, the fields are |
446 | 446 | displayed in the order in which you define them in your form class. For |
447 | 447 | example, in the ``ContactForm`` example, the fields are defined in the order |
448 | 448 | ``subject``, ``message``, ``sender``, ``cc_myself``. To reorder the HTML |
… |
… |
|
451 | 451 | How errors are displayed |
452 | 452 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
453 | 453 | |
454 | | If you render a bound ``Form`` object, the act of rendering will automatically |
| 454 | If you render a bound :class:`Form` object, the act of rendering will automatically |
455 | 455 | run the form's validation if it hasn't already happened, and the HTML output |
456 | 456 | will include the validation errors as a ``<ul class="errorlist">`` near the |
457 | 457 | field. The particular positioning of the error messages depends on the output |
… |
… |
|
483 | 483 | Customizing the error list format |
484 | 484 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
485 | 485 | |
486 | | By default, forms use ``django.forms.util.ErrorList`` to format validation |
| 486 | By default, forms use :class:`django.forms.util.ErrorList` to format validation |
487 | 487 | errors. If you'd like to use an alternate class for displaying errors, you can |
488 | 488 | pass that in at construction time:: |
489 | 489 | |
… |
… |
|
506 | 506 | More granular output |
507 | 507 | ~~~~~~~~~~~~~~~~~~~~ |
508 | 508 | |
509 | | The ``as_p()``, ``as_ul()`` and ``as_table()`` methods are simply shortcuts for |
| 509 | The :meth:`as_p`, :meth:`as_ul` and :meth:`as_table` methods are simply shortcuts for |
510 | 510 | lazy developers -- they're not the only way a form object can be displayed. |
511 | 511 | |
512 | 512 | To display the HTML for a single field in your form, use dictionary lookup |
… |
… |
|
549 | 549 | >>> print f['message'] |
550 | 550 | <input type="text" name="message" id="id_message" /> |
551 | 551 | |
552 | | For a field's list of errors, access the field's ``errors`` attribute. This |
| 552 | For a field's list of errors, access the field's :attr:`errors` attribute. This |
553 | 553 | is a list-like object that is displayed as an HTML ``<ul class="errorlist">`` |
554 | 554 | when printed:: |
555 | 555 | |
… |
… |
|
575 | 575 | |
576 | 576 | .. versionadded:: 1.0 |
577 | 577 | |
578 | | Dealing with forms that have ``FileField`` and ``ImageField`` fields |
| 578 | Dealing with forms that have :class:`FileField` and :class:`ImageField` fields |
579 | 579 | is a little more complicated than a normal form. |
580 | 580 | |
581 | 581 | Firstly, in order to upload files, you'll need to make sure that your |
… |
… |
|
586 | 586 | |
587 | 587 | Secondly, when you use the form, you need to bind the file data. File |
588 | 588 | data is handled separately to normal form data, so when your form |
589 | | contains a ``FileField`` and ``ImageField``, you will need to specify |
| 589 | contains a :class:`FileField` and :class:`ImageField`, you will need to specify |
590 | 590 | a second argument when you bind your form. So if we extend our |
591 | | ContactForm to include an ``ImageField`` called ``mugshot``, we |
| 591 | ContactForm to include an :class:`ImageField` called ``mugshot``, we |
592 | 592 | need to bind the file data containing the mugshot image:: |
593 | 593 | |
594 | 594 | # Bound form with an image field |
… |
… |
|
600 | 600 | >>> file_data = {'mugshot': SimpleUploadedFile('face.jpg', <file data>)} |
601 | 601 | >>> f = ContactFormWithMugshot(data, file_data) |
602 | 602 | |
603 | | In practice, you will usually specify ``request.FILES`` as the source |
604 | | of file data (just like you use ``request.POST`` as the source of |
| 603 | In practice, you will usually specify :attr:`request.FILES` as the source |
| 604 | of file data (just like you use :attr:`request.POST` as the source of |
605 | 605 | form data):: |
606 | 606 | |
607 | 607 | # Bound form with an image field, data from the request |
… |
… |
|
617 | 617 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
618 | 618 | |
619 | 619 | If you're writing reusable views or templates, you may not know ahead of time |
620 | | whether your form is a multipart form or not. The ``is_multipart()`` method |
| 620 | whether your form is a multipart form or not. The :meth:`is_multipart` method |
621 | 621 | tells you whether the form requires multipart encoding for submission:: |
622 | 622 | |
623 | 623 | >>> f = ContactFormWithMugshot() |
… |
… |
|
637 | 637 | Subclassing forms |
638 | 638 | ----------------- |
639 | 639 | |
640 | | If you have multiple ``Form`` classes that share fields, you can use |
| 640 | If you have multiple :class:`Form` classes that share fields, you can use |
641 | 641 | subclassing to remove redundancy. |
642 | 642 | |
643 | | When you subclass a custom ``Form`` class, the resulting subclass will |
| 643 | When you subclass a custom :class:`Form` class, the resulting subclass will |
644 | 644 | include all fields of the parent class(es), followed by the fields you define |
645 | 645 | in the subclass. |
646 | 646 | |
… |
… |
|
685 | 685 | .. attribute:: Form.prefix |
686 | 686 | |
687 | 687 | You can put several Django forms inside one ``<form>`` tag. To give each |
688 | | ``Form`` its own namespace, use the ``prefix`` keyword argument:: |
| 688 | :class:`Form` its own namespace, use the ``prefix`` keyword argument:: |
689 | 689 | |
690 | 690 | >>> mother = PersonForm(prefix="mother") |
691 | 691 | >>> father = PersonForm(prefix="father") |
-
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
a
|
b
|
|
725 | 725 | .. attribute:: URLField.validator_user_agent |
726 | 726 | |
727 | 727 | String used as the user-agent used when checking for a URL's existence. |
728 | | Defaults to the value of the ``URL_VALIDATOR_USER_AGENT`` setting. |
| 728 | Defaults to the value of the :setting:`URL_VALIDATOR_USER_AGENT` setting. |
729 | 729 | |
730 | 730 | Slightly complex built-in ``Field`` classes |
731 | 731 | ------------------------------------------- |
-
diff --git a/docs/ref/generic-views.txt b/docs/ref/generic-views.txt
a
|
b
|
|
73 | 73 | "Simple" generic views |
74 | 74 | ====================== |
75 | 75 | |
76 | | The ``django.views.generic.simple`` module contains simple views to handle a |
| 76 | The :mod:`django.views.generic.simple` module contains simple views to handle a |
77 | 77 | couple of common cases: rendering a template when no view logic is needed, |
78 | 78 | and issuing a redirect. |
79 | 79 | |
… |
… |
|
97 | 97 | just before rendering the template. |
98 | 98 | |
99 | 99 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
100 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 100 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
101 | 101 | |
102 | 102 | **Example:** |
103 | 103 | |
… |
… |
|
204 | 204 | page. This lets you override the default template name (see below). |
205 | 205 | |
206 | 206 | * ``template_loader``: The template loader to use when loading the |
207 | | template. By default, it's ``django.template.loader``. |
| 207 | template. By default, it's :mod:`django.template.loader`. |
208 | 208 | |
209 | 209 | * ``extra_context``: A dictionary of values to add to the template |
210 | 210 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
220 | 220 | the view's template. |
221 | 221 | |
222 | 222 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
223 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 223 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
224 | 224 | |
225 | 225 | * ``allow_future``: A boolean specifying whether to include "future" |
226 | 226 | objects on this page, where "future" means objects in which the field |
… |
… |
|
289 | 289 | page. This lets you override the default template name (see below). |
290 | 290 | |
291 | 291 | * ``template_loader``: The template loader to use when loading the |
292 | | template. By default, it's ``django.template.loader``. |
| 292 | template. By default, it's :mod:`django.template.loader`. |
293 | 293 | |
294 | 294 | * ``extra_context``: A dictionary of values to add to the template |
295 | 295 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
317 | 317 | this is ``False``. |
318 | 318 | |
319 | 319 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
320 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 320 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
321 | 321 | |
322 | 322 | * ``allow_future``: A boolean specifying whether to include "future" |
323 | 323 | objects on this page, where "future" means objects in which the field |
… |
… |
|
383 | 383 | page. This lets you override the default template name (see below). |
384 | 384 | |
385 | 385 | * ``template_loader``: The template loader to use when loading the |
386 | | template. By default, it's ``django.template.loader``. |
| 386 | template. By default, it's :mod:`django.template.loader`. |
387 | 387 | |
388 | 388 | * ``extra_context``: A dictionary of values to add to the template |
389 | 389 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
404 | 404 | determining the variable's name. |
405 | 405 | |
406 | 406 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
407 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 407 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
408 | 408 | |
409 | 409 | * ``allow_future``: A boolean specifying whether to include "future" |
410 | 410 | objects on this page, where "future" means objects in which the field |
… |
… |
|
464 | 464 | page. This lets you override the default template name (see below). |
465 | 465 | |
466 | 466 | * ``template_loader``: The template loader to use when loading the |
467 | | template. By default, it's ``django.template.loader``. |
| 467 | template. By default, it's :mod:`django.template.loader`. |
468 | 468 | |
469 | 469 | * ``extra_context``: A dictionary of values to add to the template |
470 | 470 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
485 | 485 | determining the variable's name. |
486 | 486 | |
487 | 487 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
488 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 488 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
489 | 489 | |
490 | 490 | * ``allow_future``: A boolean specifying whether to include "future" |
491 | 491 | objects on this page, where "future" means objects in which the field |
… |
… |
|
549 | 549 | page. This lets you override the default template name (see below). |
550 | 550 | |
551 | 551 | * ``template_loader``: The template loader to use when loading the |
552 | | template. By default, it's ``django.template.loader``. |
| 552 | template. By default, it's :mod:`django.template.loader`. |
553 | 553 | |
554 | 554 | * ``extra_context``: A dictionary of values to add to the template |
555 | 555 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
570 | 570 | determining the variable's name. |
571 | 571 | |
572 | 572 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
573 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 573 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
574 | 574 | |
575 | 575 | * ``allow_future``: A boolean specifying whether to include "future" |
576 | 576 | objects on this page, where "future" means objects in which the field |
… |
… |
|
666 | 666 | It's a bit of a brain-bender, but it's useful in some cases. |
667 | 667 | |
668 | 668 | * ``template_loader``: The template loader to use when loading the |
669 | | template. By default, it's ``django.template.loader``. |
| 669 | template. By default, it's :mod:`django.template.loader`. |
670 | 670 | |
671 | 671 | * ``extra_context``: A dictionary of values to add to the template |
672 | 672 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
680 | 680 | to use in the template context. By default, this is ``'object'``. |
681 | 681 | |
682 | 682 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
683 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 683 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
684 | 684 | |
685 | 685 | * ``allow_future``: A boolean specifying whether to include "future" |
686 | 686 | objects on this page, where "future" means objects in which the field |
… |
… |
|
735 | 735 | page. This lets you override the default template name (see below). |
736 | 736 | |
737 | 737 | * ``template_loader``: The template loader to use when loading the |
738 | | template. By default, it's ``django.template.loader``. |
| 738 | template. By default, it's :mod:`django.template.loader`. |
739 | 739 | |
740 | 740 | * ``extra_context``: A dictionary of values to add to the template |
741 | 741 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
756 | 756 | determining the variable's name. |
757 | 757 | |
758 | 758 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
759 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 759 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
760 | 760 | |
761 | 761 | **Template name:** |
762 | 762 | |
… |
… |
|
861 | 861 | It's a bit of a brain-bender, but it's useful in some cases. |
862 | 862 | |
863 | 863 | * ``template_loader``: The template loader to use when loading the |
864 | | template. By default, it's ``django.template.loader``. |
| 864 | template. By default, it's :mod:`django.template.loader`. |
865 | 865 | |
866 | 866 | * ``extra_context``: A dictionary of values to add to the template |
867 | 867 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
875 | 875 | to use in the template context. By default, this is ``'object'``. |
876 | 876 | |
877 | 877 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
878 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 878 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
879 | 879 | |
880 | 880 | **Template name:** |
881 | 881 | |
… |
… |
|
944 | 944 | page. This lets you override the default template name (see below). |
945 | 945 | |
946 | 946 | * ``template_loader``: The template loader to use when loading the |
947 | | template. By default, it's ``django.template.loader``. |
| 947 | template. By default, it's :mod:`django.template.loader`. |
948 | 948 | |
949 | 949 | * ``extra_context``: A dictionary of values to add to the template |
950 | 950 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
1029 | 1029 | page. This lets you override the default template name (see below). |
1030 | 1030 | |
1031 | 1031 | * ``template_loader``: The template loader to use when loading the |
1032 | | template. By default, it's ``django.template.loader``. |
| 1032 | template. By default, it's :mod:`django.template.loader`. |
1033 | 1033 | |
1034 | 1034 | * ``extra_context``: A dictionary of values to add to the template |
1035 | 1035 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
1111 | 1111 | page. This lets you override the default template name (see below). |
1112 | 1112 | |
1113 | 1113 | * ``template_loader``: The template loader to use when loading the |
1114 | | template. By default, it's ``django.template.loader``. |
| 1114 | template. By default, it's :mod:`django.template.loader`. |
1115 | 1115 | |
1116 | 1116 | * ``extra_context``: A dictionary of values to add to the template |
1117 | 1117 | context. By default, this is an empty dictionary. If a value in the |
-
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
a
|
b
|
|
52 | 52 | .. versionadded:: 1.0 |
53 | 53 | |
54 | 54 | A string representing the current encoding used to decode form submission |
55 | | data (or ``None``, which means the ``DEFAULT_CHARSET`` setting is used). |
| 55 | data (or ``None``, which means the :setting:`DEFAULT_CHARSET` setting is used). |
56 | 56 | You can write to this attribute to change the encoding used when accessing |
57 | 57 | the form data. Any subsequent attribute accesses (such as reading from |
58 | 58 | ``GET`` or ``POST``) will use the new ``encoding`` value. Useful if you |
… |
… |
|
61 | 61 | .. attribute:: HttpRequest.GET |
62 | 62 | |
63 | 63 | A dictionary-like object containing all given HTTP GET parameters. See the |
64 | | ``QueryDict`` documentation below. |
| 64 | :class:`QueryDict` documentation below. |
65 | 65 | |
66 | 66 | .. attribute:: HttpRequest.POST |
67 | 67 | |
68 | 68 | A dictionary-like object containing all given HTTP POST parameters. See the |
69 | | ``QueryDict`` documentation below. |
| 69 | :class:`QueryDict` documentation below. |
70 | 70 | |
71 | 71 | It's possible that a request can come in via POST with an empty ``POST`` |
72 | 72 | dictionary -- if, say, a form is requested via the POST HTTP method but |
… |
… |
|
97 | 97 | |
98 | 98 | A dictionary-like object containing all uploaded files. Each key in |
99 | 99 | ``FILES`` is the ``name`` from the ``<input type="file" name="" />``. Each |
100 | | value in ``FILES`` is an ``UploadedFile`` object containing the following |
| 100 | value in ``FILES`` is an :class:`UploadedFile` object containing the following |
101 | 101 | attributes: |
102 | 102 | |
103 | 103 | * ``read(num_bytes=None)`` -- Read a number of bytes from the file. |
… |
… |
|
151 | 151 | |
152 | 152 | .. attribute:: HttpRequest.user |
153 | 153 | |
154 | | A ``django.contrib.auth.models.User`` object representing the currently |
| 154 | A :class:`django.contrib.auth.models.User` object representing the currently |
155 | 155 | logged-in user. If the user isn't currently logged in, ``user`` will be set |
156 | | to an instance of ``django.contrib.auth.models.AnonymousUser``. You |
157 | | can tell them apart with ``is_authenticated()``, like so:: |
| 156 | to an instance of :class:`django.contrib.auth.models.AnonymousUser`. You |
| 157 | can tell them apart with :meth:`is_authenticated`, like so:: |
158 | 158 | |
159 | 159 | if request.user.is_authenticated(): |
160 | 160 | # Do something for logged-in users. |
… |
… |
|
181 | 181 | |
182 | 182 | Not defined by Django itself, but will be read if other code (e.g., a custom |
183 | 183 | middleware class) sets it. When present, this will be used as the root |
184 | | URLconf for the current request, overriding the ``ROOT_URLCONF`` setting. |
| 184 | URLconf for the current request, overriding the :setting:`ROOT_URLCONF` setting. |
185 | 185 | See :ref:`how-django-processes-a-request` for details. |
186 | 186 | |
187 | 187 | Methods |
… |
… |
|
249 | 249 | .. class:: QueryDict |
250 | 250 | |
251 | 251 | In an :class:`HttpRequest` object, the ``GET`` and ``POST`` attributes are instances |
252 | | of ``django.http.QueryDict``. :class:`QueryDict` is a dictionary-like |
| 252 | of ``django.http.QueryDict``. ``QueryDict`` is a dictionary-like |
253 | 253 | class customized to deal with multiple values for the same key. This is |
254 | 254 | necessary because some HTML form elements, notably |
255 | 255 | ``<select multiple="multiple">``, pass multiple values for the same key. |
… |
… |
|
261 | 261 | Methods |
262 | 262 | ------- |
263 | 263 | |
264 | | :class:`QueryDict` implements all the standard dictionary methods, because it's |
| 264 | ``QueryDict`` implements all the standard dictionary methods, because it's |
265 | 265 | a subclass of dictionary. Exceptions are outlined here: |
266 | 266 | |
267 | 267 | .. method:: QueryDict.__getitem__(key) |
… |
… |
|
294 | 294 | Just like the standard dictionary ``setdefault()`` method, except it uses |
295 | 295 | ``__setitem__`` internally. |
296 | 296 | |
297 | | .. method:: QueryDict.update(other_dict) |
| 297 | .. method:: QueryDict.update(other_dict) |
298 | 298 | |
299 | 299 | Takes either a ``QueryDict`` or standard dictionary. Just like the standard |
300 | 300 | dictionary ``update()`` method, except it *appends* to the current |
… |
… |
|
357 | 357 | |
358 | 358 | Like :meth:`items()`, except it includes all values, as a list, for each |
359 | 359 | member of the dictionary. For example:: |
360 | | |
| 360 | |
361 | 361 | >>> q = QueryDict('a=1&a=2&a=3') |
362 | 362 | >>> q.lists() |
363 | 363 | [('a', ['1', '2', '3'])] |
364 | | |
| 364 | |
365 | 365 | .. method:: QueryDict.urlencode() |
366 | 366 | |
367 | 367 | Returns a string of the data in query-string format. |
… |
… |
|
373 | 373 | .. class:: HttpResponse |
374 | 374 | |
375 | 375 | In contrast to :class:`HttpRequest` objects, which are created automatically by |
376 | | Django, :class:`HttpResponse` objects are your responsibility. Each view you |
| 376 | Django, ``HttpResponse`` objects are your responsibility. Each view you |
377 | 377 | write is responsible for instantiating, populating and returning an |
378 | | :class:`HttpResponse`. |
| 378 | ``HttpResponse``. |
379 | 379 | |
380 | | The :class:`HttpResponse` class lives in the ``django.http`` module. |
| 380 | The ``HttpResponse`` class lives in the :mod:`django.http` module. |
381 | 381 | |
382 | 382 | Usage |
383 | 383 | ----- |
… |
… |
|
386 | 386 | ~~~~~~~~~~~~~~~ |
387 | 387 | |
388 | 388 | Typical usage is to pass the contents of the page, as a string, to the |
389 | | :class:`HttpResponse` constructor:: |
| 389 | ``HttpResponse`` constructor:: |
390 | 390 | |
391 | 391 | >>> response = HttpResponse("Here's the text of the Web page.") |
392 | 392 | >>> response = HttpResponse("Text only, please.", mimetype="text/plain") |
… |
… |
|
415 | 415 | hard-coded strings. If you use this technique, follow these guidelines: |
416 | 416 | |
417 | 417 | * The iterator should return strings. |
418 | | * If an :class:`HttpResponse` has been initialized with an iterator as its |
419 | | content, you can't use the class:`HttpResponse` instance as a file-like |
| 418 | * If an ``HttpResponse`` has been initialized with an iterator as its |
| 419 | content, you can't use the ``HttpResponse`` instance as a file-like |
420 | 420 | object. Doing so will raise ``Exception``. |
421 | 421 | |
422 | 422 | Setting headers |
… |
… |
|
452 | 452 | ------- |
453 | 453 | |
454 | 454 | .. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE) |
455 | | |
| 455 | |
456 | 456 | Instantiates an ``HttpResponse`` object with the given page content (a |
457 | | string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``. |
| 457 | string) and MIME type. The :setting:`DEFAULT_CONTENT_TYPE` is ``'text/html'``. |
458 | 458 | |
459 | 459 | ``content`` can be an iterator or a string. If it's an iterator, it should |
460 | 460 | return strings, and those strings will be joined together to form the |
… |
… |
|
470 | 470 | encoding, which makes it more than just a MIME type specification. |
471 | 471 | If ``mimetype`` is specified (not ``None``), that value is used. |
472 | 472 | Otherwise, ``content_type`` is used. If neither is given, the |
473 | | ``DEFAULT_CONTENT_TYPE`` setting is used. |
| 473 | :setting:`DEFAULT_CONTENT_TYPE` setting is used. |
474 | 474 | |
475 | 475 | .. method:: HttpResponse.__setitem__(header, value) |
476 | 476 | |
… |
… |
|
519 | 519 | |
520 | 520 | .. method:: HttpResponse.write(content) |
521 | 521 | |
522 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 522 | This method makes an ``HttpResponse`` instance a file-like object. |
523 | 523 | |
524 | 524 | .. method:: HttpResponse.flush() |
525 | 525 | |
526 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 526 | This method makes an ``HttpResponse`` instance a file-like object. |
527 | 527 | |
528 | 528 | .. method:: HttpResponse.tell() |
529 | 529 | |
530 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 530 | This method makes an ``HttpResponse`` instance a file-like object. |
531 | 531 | |
532 | 532 | .. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 |
533 | 533 | |
… |
… |
|
537 | 537 | HttpResponse subclasses |
538 | 538 | ----------------------- |
539 | 539 | |
540 | | Django includes a number of ``HttpResponse`` subclasses that handle different |
| 540 | Django includes a number of :class:`HttpResponse` subclasses that handle different |
541 | 541 | types of HTTP responses. Like ``HttpResponse``, these subclasses live in |
542 | 542 | :mod:`django.http`. |
543 | 543 | |
-
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
a
|
b
|
|
47 | 47 | |
48 | 48 | The URL prefix for admin media -- CSS, JavaScript and images used by |
49 | 49 | the Django administrative interface. Make sure to use a trailing |
50 | | slash, and to have this be different from the ``MEDIA_URL`` setting |
| 50 | slash, and to have this be different from the :setting:`MEDIA_URL` setting |
51 | 51 | (since the same URL cannot be mapped onto two different sets of |
52 | 52 | files). |
53 | 53 | |
… |
… |
|
92 | 92 | |
93 | 93 | Whether to append trailing slashes to URLs. This is only used if |
94 | 94 | ``CommonMiddleware`` is installed (see :ref:`topics-http-middleware`). See also |
95 | | ``PREPEND_WWW``. |
| 95 | :setting:`PREPEND_WWW`. |
96 | 96 | |
97 | 97 | .. setting:: AUTHENTICATION_BACKENDS |
98 | 98 | |
… |
… |
|
195 | 195 | Default: ``''`` (Empty string) |
196 | 196 | |
197 | 197 | The name of the database to use. For SQLite, it's the full path to the database |
198 | | file. When specifying the path, always use forward slashes, even on Windows |
| 198 | file. When specifying the path, always use forward slashes, even on Windows |
199 | 199 | (e.g. ``C:/homes/user/mysite/sqlite3.db``). |
200 | 200 | |
201 | 201 | .. setting:: DATABASE_OPTIONS |
… |
… |
|
228 | 228 | default port. Not used with SQLite. |
229 | 229 | |
230 | 230 | .. setting:: DATABASE_USER |
231 | | |
| 231 | |
232 | 232 | DATABASE_USER |
233 | 233 | ------------- |
234 | 234 | |
… |
… |
|
251 | 251 | and ``MONTH_DAY_FORMAT``. |
252 | 252 | |
253 | 253 | .. setting:: DATETIME_FORMAT |
254 | | |
| 254 | |
255 | 255 | DATETIME_FORMAT |
256 | 256 | --------------- |
257 | 257 | |
… |
… |
|
519 | 519 | .. warning:: |
520 | 520 | |
521 | 521 | **Always prefix the mode with a 0.** |
522 | | |
| 522 | |
523 | 523 | If you're not familiar with file modes, please note that the leading |
524 | 524 | ``0`` is very important: it indicates an octal number, which is the |
525 | 525 | way that modes must be specified. If you try to use ``644``, you'll |
526 | 526 | get totally incorrect behavior. |
527 | | |
528 | 527 | |
529 | | .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html |
| 528 | |
| 529 | .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html |
530 | 530 | |
531 | 531 | .. setting:: FIXTURE_DIRS |
532 | 532 | |
… |
… |
|
650 | 650 | |
651 | 651 | If you define a custom ``LANGUAGES`` setting, it's OK to mark the languages as |
652 | 652 | translation strings (as in the default value displayed above) -- but use a |
653 | | "dummy" ``gettext()`` function, not the one in ``django.utils.translation``. |
654 | | You should *never* import ``django.utils.translation`` from within your |
| 653 | "dummy" ``gettext()`` function, not the one in :mod:`django.utils.translation`. |
| 654 | You should *never* import :mod:`django.utils.translation` from within your |
655 | 655 | settings file, because that module in itself depends on the settings, and that |
656 | 656 | would cause a circular import. |
657 | 657 | |
… |
… |
|
875 | 875 | |
876 | 876 | .. versionadded:: 1.0 |
877 | 877 | |
878 | | Default: ``django.contrib.sessions.backends.db`` |
| 878 | Default: :mod:`django.contrib.sessions.backends.db` |
879 | 879 | |
880 | 880 | Controls where Django stores session data. Valid values are: |
881 | 881 | |
… |
… |
|
1165 | 1165 | Django cannot reliably use alternate time zones in a Windows environment. |
1166 | 1166 | If you're running Django on Windows, this variable must be set to match the |
1167 | 1167 | system timezone. |
1168 | | |
| 1168 | |
1169 | 1169 | .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE |
1170 | 1170 | |
1171 | 1171 | .. setting:: URL_VALIDATOR_USER_AGENT |
-
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
a
|
b
|
|
562 | 562 | To cut down on the repetitive nature of loading and rendering |
563 | 563 | templates, Django provides a shortcut function which largely |
564 | 564 | automates the process: ``render_to_string()`` in |
565 | | ``django.template.loader``, which loads a template, renders it and |
| 565 | :mod:`django.template.loader`, which loads a template, renders it and |
566 | 566 | returns the resulting string:: |
567 | 567 | |
568 | 568 | from django.template.loader import render_to_string |
-
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
a
|
b
|
|
1616 | 1616 | ------------------------------- |
1617 | 1617 | |
1618 | 1618 | Django comes with a couple of other template-tag libraries that you have to |
1619 | | enable explicitly in your ``INSTALLED_APPS`` setting and enable in your |
| 1619 | enable explicitly in your :setting:`INSTALLED_APPS` setting and enable in your |
1620 | 1620 | template with the ``{% load %}`` tag. |
1621 | 1621 | |
1622 | 1622 | django.contrib.humanize |
-
diff --git a/docs/ref/unicode.txt b/docs/ref/unicode.txt
a
|
b
|
|
107 | 107 | Conversion functions |
108 | 108 | ~~~~~~~~~~~~~~~~~~~~ |
109 | 109 | |
110 | | The ``django.utils.encoding`` module contains a few functions that are handy |
| 110 | The :mod:`django.utils.encoding` module contains a few functions that are handy |
111 | 111 | for converting back and forth between Unicode and bytestrings. |
112 | 112 | |
113 | 113 | * ``smart_unicode(s, encoding='utf-8', strings_only=False, errors='strict')`` |
… |
… |
|
311 | 311 | E-mail |
312 | 312 | ====== |
313 | 313 | |
314 | | Django's e-mail framework (in ``django.core.mail``) supports Unicode |
| 314 | Django's e-mail framework (in :mod:`django.core.mail`) supports Unicode |
315 | 315 | transparently. You can use Unicode data in the message bodies and any headers. |
316 | 316 | However, you're still obligated to respect the requirements of the e-mail |
317 | 317 | specifications, so, for example, e-mail addresses should use only ASCII |
-
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
a
|
b
|
|
27 | 27 | ============ |
28 | 28 | |
29 | 29 | Authentication support is bundled as a Django application in |
30 | | ``django.contrib.auth``. To install it, do the following: |
| 30 | :mod:`django.contrib.auth`. To install it, do the following: |
31 | 31 | |
32 | 32 | 1. Put ``'django.contrib.auth'`` in your :setting:`INSTALLED_APPS` setting. |
33 | 33 | 2. Run the command ``manage.py syncdb``. |
… |
… |
|
680 | 680 | |
681 | 681 | .. function:: views.login() |
682 | 682 | |
683 | | Here's what ``django.contrib.auth.views.login`` does: |
| 683 | Here's what :func:`django.contrib.auth.views.login` does: |
684 | 684 | |
685 | 685 | * If called via ``GET``, it displays a login form that POSTs to the same |
686 | 686 | URL. More on this in a bit. |
… |
… |
|
1000 | 1000 | Default permissions |
1001 | 1001 | ------------------- |
1002 | 1002 | |
1003 | | When ``django.contrib.auth`` is listed in your :setting:`INSTALLED_APPS` |
| 1003 | When :mod:`django.contrib.auth` is listed in your :setting:`INSTALLED_APPS` |
1004 | 1004 | setting, it will ensure that three default permissions -- add, change |
1005 | 1005 | and delete -- are created for each Django model defined in one of your |
1006 | 1006 | installed applications. |
1007 | 1007 | |
1008 | 1008 | These permissions will be created when you run |
1009 | 1009 | :djadmin:`manage.py syncdb <syncdb>`; the first time you run ``syncdb`` after |
1010 | | adding ``django.contrib.auth`` to :setting:`INSTALLED_APPS`, the default |
| 1010 | adding :mod:`django.contrib.auth` to :setting:`INSTALLED_APPS`, the default |
1011 | 1011 | permissions will be created for all previously-installed models, as well as |
1012 | 1012 | for any new models being installed at that time. Afterward, it will create |
1013 | 1013 | default permissions for new models each time you run |
-
diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt
a
|
b
|
|
49 | 49 | or directly in memory. This is an important decision that affects your cache's |
50 | 50 | performance; yes, some cache types are faster than others. |
51 | 51 | |
52 | | Your cache preference goes in the ``CACHE_BACKEND`` setting in your settings |
| 52 | Your cache preference goes in the :setting:`CACHE_BACKEND` setting in your settings |
53 | 53 | file. Here's an explanation of all available values for CACHE_BACKEND. |
54 | 54 | |
55 | 55 | Memcached |
… |
… |
|
84 | 84 | The ``cmemcache`` option is new in 1.0. Previously, only |
85 | 85 | ``python-memcached`` was supported. |
86 | 86 | |
87 | | To use Memcached with Django, set ``CACHE_BACKEND`` to |
| 87 | To use Memcached with Django, set :setting:`CACHE_BACKEND` to |
88 | 88 | ``memcached://ip:port/``, where ``ip`` is the IP address of the Memcached |
89 | 89 | daemon and ``port`` is the port on which Memcached is running. |
90 | 90 | |
… |
… |
|
94 | 94 | |
95 | 95 | One excellent feature of Memcached is its ability to share cache over multiple |
96 | 96 | servers. To take advantage of this feature, include all server addresses in |
97 | | ``CACHE_BACKEND``, separated by semicolons. In this example, the cache is |
| 97 | :setting:`CACHE_BACKEND`, separated by semicolons. In this example, the cache is |
98 | 98 | shared over Memcached instances running on IP address 172.19.26.240 and |
99 | 99 | 172.19.26.242, both on port 11211:: |
100 | 100 | |
… |
… |
|
122 | 122 | in your database that is in the proper format that Django's database-cache |
123 | 123 | system expects. |
124 | 124 | |
125 | | Once you've created that database table, set your ``CACHE_BACKEND`` setting to |
| 125 | Once you've created that database table, set your :setting:`CACHE_BACKEND` setting to |
126 | 126 | ``"db://tablename"``, where ``tablename`` is the name of the database table. |
127 | 127 | In this example, the cache table's name is ``my_cache_table``:: |
128 | 128 | |
… |
… |
|
134 | 134 | ------------------ |
135 | 135 | |
136 | 136 | To store cached items on a filesystem, use the ``"file://"`` cache type for |
137 | | ``CACHE_BACKEND``. For example, to store cached data in ``/var/tmp/django_cache``, |
| 137 | :setting:`CACHE_BACKEND`. For example, to store cached data in ``/var/tmp/django_cache``, |
138 | 138 | use this setting:: |
139 | 139 | |
140 | 140 | CACHE_BACKEND = 'file:///var/tmp/django_cache' |
… |
… |
|
158 | 158 | |
159 | 159 | If you want the speed advantages of in-memory caching but don't have the |
160 | 160 | capability of running Memcached, consider the local-memory cache backend. This |
161 | | cache is multi-process and thread-safe. To use it, set ``CACHE_BACKEND`` to |
| 161 | cache is multi-process and thread-safe. To use it, set :setting:`CACHE_BACKEND` to |
162 | 162 | ``"locmem:///"``. For example:: |
163 | 163 | |
164 | 164 | CACHE_BACKEND = 'locmem:///' |
… |
… |
|
178 | 178 | various places but a development/test environment on which you don't want to |
179 | 179 | cache. As a result, your development environment won't use caching and your |
180 | 180 | production environment still will. To activate dummy caching, set |
181 | | ``CACHE_BACKEND`` like so:: |
| 181 | :setting:`CACHE_BACKEND` like so:: |
182 | 182 | |
183 | 183 | CACHE_BACKEND = 'dummy:///' |
184 | 184 | |
… |
… |
|
190 | 190 | While Django includes support for a number of cache backends out-of-the-box, |
191 | 191 | sometimes you might want to use a customized cache backend. To use an external |
192 | 192 | cache backend with Django, use a Python import path as the scheme portion (the |
193 | | part before the initial colon) of the ``CACHE_BACKEND`` URI, like so:: |
| 193 | part before the initial colon) of the :setting:`CACHE_BACKEND` URI, like so:: |
194 | 194 | |
195 | 195 | CACHE_BACKEND = 'path.to.backend://' |
196 | 196 | |
… |
… |
|
206 | 206 | ----------------------- |
207 | 207 | |
208 | 208 | All caches may take arguments. They're given in query-string style on the |
209 | | ``CACHE_BACKEND`` setting. Valid arguments are: |
| 209 | :setting:`CACHE_BACKEND` setting. Valid arguments are: |
210 | 210 | |
211 | 211 | timeout |
212 | 212 | Default timeout, in seconds, to use for the cache. Defaults to 5 |
… |
… |
|
248 | 248 | entire site. You'll need to add |
249 | 249 | ``'django.middleware.cache.UpdateCacheMiddleware'`` and |
250 | 250 | ``'django.middleware.cache.FetchFromCacheMiddleware'`` to your |
251 | | ``MIDDLEWARE_CLASSES`` setting, as in this example:: |
| 251 | :setting:`MIDDLEWARE_CLASSES` setting, as in this example:: |
252 | 252 | |
253 | 253 | MIDDLEWARE_CLASSES = ( |
254 | 254 | 'django.middleware.cache.UpdateCacheMiddleware', |
… |
… |
|
264 | 264 | |
265 | 265 | Then, add the following required settings to your Django settings file: |
266 | 266 | |
267 | | * ``CACHE_MIDDLEWARE_SECONDS`` -- The number of seconds each page should be |
| 267 | * :setting:`CACHE_MIDDLEWARE_SECONDS` -- The number of seconds each page should be |
268 | 268 | cached. |
269 | | * ``CACHE_MIDDLEWARE_KEY_PREFIX`` -- If the cache is shared across multiple |
| 269 | * :setting:`CACHE_MIDDLEWARE_KEY_PREFIX` -- If the cache is shared across multiple |
270 | 270 | sites using the same Django installation, set this to the name of the site, |
271 | 271 | or some other string that is unique to this Django instance, to prevent key |
272 | 272 | collisions. Use an empty string if you don't care. |
273 | 273 | |
274 | 274 | The cache middleware caches every page that doesn't have GET or POST |
275 | | parameters. Optionally, if the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is |
| 275 | parameters. Optionally, if the :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY` setting is |
276 | 276 | ``True``, only anonymous requests (i.e., not those made by a logged-in user) |
277 | 277 | will be cached. This is a simple and effective way of disabling caching for any |
278 | 278 | user-specific pages (include Django's admin interface). Note that if you use |
279 | | ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY``, you should make sure you've activated |
| 279 | :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY`, you should make sure you've activated |
280 | 280 | ``AuthenticationMiddleware``. |
281 | 281 | |
282 | 282 | Additionally, the cache middleware automatically sets a few headers in each |
… |
… |
|
285 | 285 | * Sets the ``Last-Modified`` header to the current date/time when a fresh |
286 | 286 | (uncached) version of the page is requested. |
287 | 287 | * Sets the ``Expires`` header to the current date/time plus the defined |
288 | | ``CACHE_MIDDLEWARE_SECONDS``. |
| 288 | :setting:`CACHE_MIDDLEWARE_SECONDS`. |
289 | 289 | * Sets the ``Cache-Control`` header to give a max age for the page -- again, |
290 | | from the ``CACHE_MIDDLEWARE_SECONDS`` setting. |
| 290 | from the :setting:`CACHE_MIDDLEWARE_SECONDS` setting. |
291 | 291 | |
292 | 292 | See :ref:`topics-http-middleware` for more on middleware. |
293 | 293 | |
… |
… |
|
295 | 295 | |
296 | 296 | If a view sets its own cache expiry time (i.e. it has a ``max-age`` section in |
297 | 297 | its ``Cache-Control`` header) then the page will be cached until the expiry |
298 | | time, rather than ``CACHE_MIDDLEWARE_SECONDS``. Using the decorators in |
299 | | ``django.views.decorators.cache`` you can easily set a view's expiry time |
| 298 | time, rather than :setting:`CACHE_MIDDLEWARE_SECONDS`. Using the decorators in |
| 299 | :mod:`django.views.decorators.cache` you can easily set a view's expiry time |
300 | 300 | (using the ``cache_control`` decorator) or disable caching for a view (using |
301 | 301 | the ``never_cache`` decorator). See the `using other headers`__ section for |
302 | 302 | more on these decorators. |
… |
… |
|
307 | 307 | ================== |
308 | 308 | |
309 | 309 | A more granular way to use the caching framework is by caching the output of |
310 | | individual views. ``django.views.decorators.cache`` defines a ``cache_page`` |
| 310 | individual views. :mod:`django.views.decorators.cache` defines a ``cache_page`` |
311 | 311 | decorator that will automatically cache the view's response for you. It's easy |
312 | 312 | to use:: |
313 | 313 | |
… |
… |
|
379 | 379 | intensive database query. In cases like this, you can use the low-level cache |
380 | 380 | API to store objects in the cache with any level of granularity you like. |
381 | 381 | |
382 | | The cache API is simple. The cache module, ``django.core.cache``, exports a |
383 | | ``cache`` object that's automatically created from the ``CACHE_BACKEND`` |
| 382 | The cache API is simple. The cache module, :mod:`django.core.cache`, exports a |
| 383 | ``cache`` object that's automatically created from the :setting:`CACHE_BACKEND` |
384 | 384 | setting:: |
385 | 385 | |
386 | 386 | >>> from django.core.cache import cache |
… |
… |
|
392 | 392 | 'hello, world!' |
393 | 393 | |
394 | 394 | The ``timeout_seconds`` argument is optional and defaults to the ``timeout`` |
395 | | argument in the ``CACHE_BACKEND`` setting (explained above). |
| 395 | argument in the :setting:`CACHE_BACKEND` setting (explained above). |
396 | 396 | |
397 | 397 | If the object doesn't exist in the cache, ``cache.get()`` returns ``None``:: |
398 | 398 | |
… |
… |
|
618 | 618 | For explanation of Cache-Control HTTP directives, see the `Cache-Control spec`_. |
619 | 619 | |
620 | 620 | (Note that the caching middleware already sets the cache header's max-age with |
621 | | the value of the ``CACHE_MIDDLEWARE_SETTINGS`` setting. If you use a custom |
| 621 | the value of the :setting:`CACHE_MIDDLEWARE_SETTINGS` setting. If you use a custom |
622 | 622 | ``max_age`` in a ``cache_control`` decorator, the decorator will take |
623 | 623 | precedence, and the header values will be merged correctly.) |
624 | 624 | |
… |
… |
|
650 | 650 | =========================== |
651 | 651 | |
652 | 652 | If you use caching middleware, it's important to put each half in the right |
653 | | place within the ``MIDDLEWARE_CLASSES`` setting. That's because the cache |
| 653 | place within the :setting:`MIDDLEWARE_CLASSES` setting. That's because the cache |
654 | 654 | middleware needs to know which headers by which to vary the cache storage. |
655 | 655 | Middleware always adds something to the ``Vary`` response header when it can. |
656 | 656 | |
-
diff --git a/docs/topics/db/transactions.txt b/docs/topics/db/transactions.txt
a
|
b
|
|
32 | 32 | transactions. |
33 | 33 | |
34 | 34 | To activate this feature, just add the ``TransactionMiddleware`` middleware to |
35 | | your ``MIDDLEWARE_CLASSES`` setting:: |
| 35 | your :setting:`MIDDLEWARE_CLASSES` setting:: |
36 | 36 | |
37 | 37 | MIDDLEWARE_CLASSES = ( |
38 | 38 | 'django.contrib.sessions.middleware.SessionMiddleware', |
… |
… |
|
136 | 136 | ================================================= |
137 | 137 | |
138 | 138 | Control freaks can totally disable all transaction management by setting |
139 | | ``DISABLE_TRANSACTION_MANAGEMENT`` to ``True`` in the Django settings file. |
| 139 | :setting:`DISABLE_TRANSACTION_MANAGEMENT` to ``True`` in the Django settings file. |
140 | 140 | |
141 | 141 | If you do this, Django won't provide any automatic transaction management |
142 | 142 | whatsoever. Middleware will no longer implicitly commit transactions, and |
-
diff --git a/docs/topics/email.txt b/docs/topics/email.txt
a
|
b
|
|
11 | 11 | Django provides a couple of light wrappers over it, to make sending e-mail |
12 | 12 | extra quick. |
13 | 13 | |
14 | | The code lives in a single module: ``django.core.mail``. |
| 14 | The code lives in a single module: :mod:`django.core.mail`. |
15 | 15 | |
16 | 16 | .. _smtplib library: http://docs.python.org/library/smtplib.html |
17 | 17 | |
… |
… |
|
33 | 33 | |
34 | 34 | .. note:: |
35 | 35 | |
36 | | The character set of e-mail sent with ``django.core.mail`` will be set to |
| 36 | The character set of e-mail sent with :mod:`django.core.mail` will be set to |
37 | 37 | the value of your :setting:`DEFAULT_CHARSET` setting. |
38 | 38 | |
39 | 39 | send_mail() |
… |
… |
|
58 | 58 | possible exceptions, all of which are subclasses of ``SMTPException``. |
59 | 59 | * ``auth_user``: The optional username to use to authenticate to the SMTP |
60 | 60 | server. If this isn't provided, Django will use the value of the |
61 | | ``EMAIL_HOST_USER`` setting. |
| 61 | :setting:`EMAIL_HOST_USER` setting. |
62 | 62 | * ``auth_password``: The optional password to use to authenticate to the |
63 | 63 | SMTP server. If this isn't provided, Django will use the value of the |
64 | | ``EMAIL_HOST_PASSWORD`` setting. |
| 64 | :setting:`EMAIL_HOST_PASSWORD` setting. |
65 | 65 | |
66 | 66 | .. _smtplib docs: http://docs.python.org/library/smtplib.html |
67 | 67 | |
… |
… |
|
185 | 185 | |
186 | 186 | Django's ``send_mail()`` and ``send_mass_mail()`` functions are actually thin |
187 | 187 | wrappers that make use of the ``EmailMessage`` and ``SMTPConnection`` classes |
188 | | in ``django.core.mail``. If you ever need to customize the way Django sends |
| 188 | in :mod:`django.core.mail`. If you ever need to customize the way Django sends |
189 | 189 | e-mail, you can subclass these two classes to suit your needs. |
190 | 190 | |
191 | 191 | .. note:: |
-
diff --git a/docs/topics/files.txt b/docs/topics/files.txt
a
|
b
|
|
117 | 117 | ------------------------------------- |
118 | 118 | |
119 | 119 | Django ships with a built-in ``FileSystemStorage`` class (defined in |
120 | | ``django.core.files.storage``) which implements basic local filesystem file |
| 120 | :mod:`django.core.files.storage`) which implements basic local filesystem file |
121 | 121 | storage. Its initializer takes two arguments: |
122 | 122 | |
123 | 123 | ====================== =================================================== |
… |
… |
|
125 | 125 | ====================== =================================================== |
126 | 126 | ``location`` Optional. Absolute path to the directory that will |
127 | 127 | hold the files. If omitted, it will be set to the |
128 | | value of your ``MEDIA_ROOT`` setting. |
| 128 | value of your :setting:`MEDIA_ROOT` setting. |
129 | 129 | ``base_url`` Optional. URL that serves the files stored at this |
130 | 130 | location. If omitted, it will default to the value |
131 | | of your ``MEDIA_URL`` setting. |
| 131 | of your :setting:`MEDIA_URL` setting. |
132 | 132 | ====================== =================================================== |
133 | 133 | |
134 | 134 | For example, the following code will store uploaded files under |
135 | | ``/media/photos`` regardless of what your ``MEDIA_ROOT`` setting is:: |
| 135 | ``/media/photos`` regardless of what your :setting:`MEDIA_ROOT` setting is:: |
136 | 136 | |
137 | 137 | from django.db import models |
138 | 138 | from django.core.files.storage import FileSystemStorage |
-
diff --git a/docs/topics/forms/index.txt b/docs/topics/forms/index.txt
a
|
b
|
|
12 | 12 | |
13 | 13 | .. highlightlang:: html+django |
14 | 14 | |
15 | | ``django.forms`` is Django's form-handling library. |
| 15 | :mod:`django.forms` is Django's form-handling library. |
16 | 16 | |
17 | 17 | While it is possible to process form submissions just using Django's |
18 | 18 | :class:`~django.http.HttpRequest` class, using the form library takes care of a |
… |
… |
|
48 | 48 | |
49 | 49 | The library is decoupled from the other Django components, such as the database |
50 | 50 | layer, views and templates. It relies only on Django settings, a couple of |
51 | | ``django.utils`` helper functions and Django's internationalization hooks (but |
| 51 | :mod:`django.utils` helper functions and Django's internationalization hooks (but |
52 | 52 | you're not required to be using internationalization features to use this |
53 | 53 | library). |
54 | 54 | |
-
diff --git a/docs/topics/forms/media.txt b/docs/topics/forms/media.txt
a
|
b
|
|
29 | 29 | |
30 | 30 | If you like the widgets that the Django Admin application uses, |
31 | 31 | feel free to use them in your own application! They're all stored |
32 | | in ``django.contrib.admin.widgets``. |
| 32 | in :mod:`django.contrib.admin.widgets`. |
33 | 33 | |
34 | 34 | .. admonition:: Which JavaScript toolkit? |
35 | 35 | |
… |
… |
|
198 | 198 | Paths used to specify media can be either relative or absolute. If a path |
199 | 199 | starts with '/', 'http://' or 'https://', it will be interpreted as an absolute |
200 | 200 | path, and left as-is. All other paths will be prepended with the value of |
201 | | ``settings.MEDIA_URL``. For example, if the MEDIA_URL for your site was |
| 201 | :setting:`settings.MEDIA_URL<MEDIA_URL>`. For example, if the MEDIA_URL for your site was |
202 | 202 | ``http://media.example.com/``:: |
203 | 203 | |
204 | 204 | class CalendarWidget(forms.TextInput): |
-
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
a
|
b
|
|
64 | 64 | below) |
65 | 65 | ``NullBooleanField`` ``CharField`` |
66 | 66 | ``PhoneNumberField`` ``USPhoneNumberField`` |
67 | | (from ``django.contrib.localflavor.us``) |
| 67 | (from :mod:`django.contrib.localflavor.us`) |
68 | 68 | ``PositiveIntegerField`` ``IntegerField`` |
69 | 69 | ``PositiveSmallIntegerField`` ``IntegerField`` |
70 | 70 | ``SlugField`` ``SlugField`` |
-
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt
a
|
b
|
|
214 | 214 | |
215 | 215 | When a user uploads a file, Django passes off the file data to an *upload |
216 | 216 | handler* -- a small class that handles file data as it gets uploaded. Upload |
217 | | handlers are initially defined in the ``FILE_UPLOAD_HANDLERS`` setting, which |
| 217 | handlers are initially defined in the :setting:`FILE_UPLOAD_HANDLERS` setting, which |
218 | 218 | defaults to:: |
219 | 219 | |
220 | 220 | ("django.core.files.uploadhandler.MemoryFileUploadHandler", |
… |
… |
|
235 | 235 | Sometimes particular views require different upload behavior. In these cases, |
236 | 236 | you can override upload handlers on a per-request basis by modifying |
237 | 237 | ``request.upload_handlers``. By default, this list will contain the upload |
238 | | handlers given by ``FILE_UPLOAD_HANDLERS``, but you can modify the list as you |
| 238 | handlers given by :setting:`FILE_UPLOAD_HANDLERS`, but you can modify the list as you |
239 | 239 | would any other list. |
240 | 240 | |
241 | 241 | For instance, suppose you've written a ``ProgressBarUploadHandler`` that |
-
diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt
a
|
b
|
|
16 | 16 | |
17 | 17 | To enable session functionality, do the following: |
18 | 18 | |
19 | | * Edit the ``MIDDLEWARE_CLASSES`` setting and make sure |
20 | | ``MIDDLEWARE_CLASSES`` contains ``'django.contrib.sessions.middleware.SessionMiddleware'``. |
| 19 | * Edit the :setting:`MIDDLEWARE_CLASSES` setting and make sure |
| 20 | :setting:`MIDDLEWARE_CLASSES` contains ``'django.contrib.sessions.middleware.SessionMiddleware'``. |
21 | 21 | The default ``settings.py`` created by ``django-admin.py startproject`` has |
22 | 22 | ``SessionMiddleware`` activated. |
23 | 23 | |
24 | | * Add ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting, |
| 24 | * Add ``'django.contrib.sessions'`` to your :setting:`INSTALLED_APPS` setting, |
25 | 25 | and run ``manage.py syncdb`` to install the single database table |
26 | 26 | that stores session data. |
27 | 27 | |
… |
… |
|
30 | 30 | see `configuring the session engine`_. |
31 | 31 | |
32 | 32 | If you don't want to use sessions, you might as well remove the |
33 | | ``SessionMiddleware`` line from ``MIDDLEWARE_CLASSES`` and ``'django.contrib.sessions'`` |
34 | | from your ``INSTALLED_APPS``. It'll save you a small bit of overhead. |
| 33 | ``SessionMiddleware`` line from :setting:`MIDDLEWARE_CLASSES` and ``'django.contrib.sessions'`` |
| 34 | from your :setting:`INSTALLED_APPS`. It'll save you a small bit of overhead. |
35 | 35 | |
36 | 36 | Configuring the session engine |
37 | 37 | ============================== |
… |
… |
|
86 | 86 | Using file-based sessions |
87 | 87 | ------------------------- |
88 | 88 | |
89 | | To use file-based sessions, set the ``SESSION_ENGINE`` setting to |
| 89 | To use file-based sessions, set the :setting:`SESSION_ENGINE` setting to |
90 | 90 | ``"django.contrib.sessions.backends.file"``. |
91 | 91 | |
92 | | You might also want to set the ``SESSION_FILE_PATH`` setting (which defaults |
| 92 | You might also want to set the :setting:`SESSION_FILE_PATH` setting (which defaults |
93 | 93 | to output from ``tempfile.gettempdir()``, most likely ``/tmp``) to control |
94 | 94 | where Django stores session files. Be sure to check that your Web server has |
95 | 95 | permissions to read and write to this location. |
… |
… |
|
192 | 192 | |
193 | 193 | Returns the number of seconds until this session expires. For sessions |
194 | 194 | with no custom expiration (or those set to expire at browser close), this |
195 | | will equal ``settings.SESSION_COOKIE_AGE``. |
| 195 | will equal :setting:`setting.SESSION_COOKIE_AGE<SESSION_COOKIE_AGE>`. |
196 | 196 | |
197 | 197 | * ``get_expiry_date()`` |
198 | 198 | |
… |
… |
|
200 | 200 | |
201 | 201 | Returns the date this session will expire. For sessions with no custom |
202 | 202 | expiration (or those set to expire at browser close), this will equal the |
203 | | date ``settings.SESSION_COOKIE_AGE`` seconds from now. |
| 203 | date :setting:`settings.SESSION_COOKIE_AGE<SESSION_COOKIE_AGE>` seconds from now. |
204 | 204 | |
205 | 205 | * ``get_expire_at_browser_close()`` |
206 | 206 | |
… |
… |
|
303 | 303 | datetime.datetime(2005, 8, 20, 13, 35, 0) |
304 | 304 | >>> s.save() |
305 | 305 | |
306 | | If you're using the ``django.contrib.sessions.backends.db`` backend, each |
| 306 | If you're using the :mod:`django.contrib.sessions.backends.db` backend, each |
307 | 307 | session is just a normal Django model. The ``Session`` model is defined in |
308 | 308 | ``django/contrib/sessions/models.py``. Because it's a normal model, you can |
309 | 309 | access sessions using the normal Django database API:: |
… |
… |
|
347 | 347 | |
348 | 348 | request.session.modified = True |
349 | 349 | |
350 | | To change this default behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting |
| 350 | To change this default behavior, set the :setting:`SESSION_SAVE_EVERY_REQUEST` setting |
351 | 351 | to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save |
352 | 352 | the session to the database on every single request. |
353 | 353 | |
… |
… |
|
362 | 362 | =============================================== |
363 | 363 | |
364 | 364 | You can control whether the session framework uses browser-length sessions vs. |
365 | | persistent sessions with the ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` setting. |
| 365 | persistent sessions with the :setting:`SESSION_EXPIRE_AT_BROWSER_CLOSE` setting. |
366 | 366 | |
367 | 367 | By default, ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` is set to ``False``, which |
368 | 368 | means session cookies will be stored in users' browsers for as long as |
369 | | ``SESSION_COOKIE_AGE``. Use this if you don't want people to have to log in |
| 369 | :setting:`SESSION_COOKIE_AGE`. Use this if you don't want people to have to log in |
370 | 370 | every time they open a browser. |
371 | 371 | |
372 | 372 | If ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` is set to ``True``, Django will use |
… |
… |
|
407 | 407 | |
408 | 408 | .. versionadded:: 1.0 |
409 | 409 | |
410 | | Default: ``django.contrib.sessions.backends.db`` |
| 410 | Default: :mod:`django.contrib.sessions.backends.db` |
411 | 411 | |
412 | 412 | Controls where Django stores session data. Valid values are: |
413 | 413 | |
-
diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
a
|
b
|
|
4 | 4 | Django shortcut functions |
5 | 5 | ========================= |
6 | 6 | |
7 | | The package ``django.shortcuts`` collects helper functions and classes that |
| 7 | The package :mod:`django.shortcuts` collects helper functions and classes that |
8 | 8 | "span" multiple levels of MVC. In other words, these functions/classes |
9 | 9 | introduce controlled coupling for convenience's sake. |
10 | 10 | |
-
diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
a
|
b
|
|
37 | 37 | algorithm the system follows to determine which Python code to execute: |
38 | 38 | |
39 | 39 | 1. Django determines the root URLconf module to use. Ordinarily, |
40 | | this is the value of the ``ROOT_URLCONF`` setting, but if the incoming |
| 40 | this is the value of the :setting:`ROOT_URLCONF` setting, but if the incoming |
41 | 41 | ``HttpRequest`` object has an attribute called ``urlconf``, its value |
42 | 42 | will be used in place of the ``ROOT_URLCONF`` setting. |
43 | | |
| 43 | |
44 | 44 | 2. Django loads that Python module and looks for the variable |
45 | 45 | ``urlpatterns``. This should be a Python list, in the format returned by |
46 | 46 | the function ``django.conf.urls.defaults.patterns()``. |
47 | | |
| 47 | |
48 | 48 | 3. Django runs through each URL pattern, in order, and stops at the first |
49 | 49 | one that matches the requested URL. |
50 | | |
| 50 | |
51 | 51 | 4. Once one of the regexes matches, Django imports and calls the given |
52 | 52 | view, which is a simple Python function. The view gets passed an |
53 | 53 | :class:`~django.http.HttpRequest` as its first argument and any values |
… |
… |
|
595 | 595 | |
596 | 596 | If you need to use something similar to the :ttag:`url` template tag in |
597 | 597 | your code, Django provides the following method (in the |
598 | | ``django.core.urlresolvers`` module): |
| 598 | :mod:`django.core.urlresolvers` module): |
599 | 599 | |
600 | 600 | .. currentmodule:: django.core.urlresolvers |
601 | 601 | .. function:: reverse(viewname, urlconf=None, args=None, kwargs=None) |
-
diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt
a
|
b
|
|
32 | 32 | Let's step through this code one line at a time: |
33 | 33 | |
34 | 34 | * First, we import the class ``HttpResponse``, which lives in the |
35 | | ``django.http`` module, along with Python's ``datetime`` library. |
| 35 | :mod:`django.http` module, along with Python's ``datetime`` library. |
36 | 36 | |
37 | 37 | * Next, we define a function called ``current_datetime``. This is the view |
38 | 38 | function. Each view function takes an ``HttpRequest`` object as its first |
… |
… |
|
50 | 50 | |
51 | 51 | .. admonition:: Django's Time Zone |
52 | 52 | |
53 | | Django includes a ``TIME_ZONE`` setting that defaults to |
| 53 | Django includes a :setting:`TIME_ZONE` setting that defaults to |
54 | 54 | ``America/Chicago``. This probably isn't where you live, so you might want |
55 | 55 | to change it in your settings file. |
56 | 56 | |
… |
… |
|
165 | 165 | in the 404. |
166 | 166 | |
167 | 167 | * The 404 view is passed a ``RequestContext`` and will have access to |
168 | | variables supplied by your ``TEMPLATE_CONTEXT_PROCESSORS`` setting (e.g., |
169 | | ``MEDIA_URL``). |
| 168 | variables supplied by your :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting (e.g., |
| 169 | :setting:`MEDIA_URL`). |
170 | 170 | |
171 | | * If ``DEBUG`` is set to ``True`` (in your settings module), then your 404 |
| 171 | * If :setting:`DEBUG` is set to ``True`` (in your settings module), then your 404 |
172 | 172 | view will never be used, and the traceback will be displayed instead. |
173 | 173 | |
174 | 174 | The 500 (server error) view |
-
diff --git a/docs/topics/i18n.txt b/docs/topics/i18n.txt
a
|
b
|
|
40 | 40 | optimizations so as not to load the internationalization machinery. |
41 | 41 | |
42 | 42 | You'll probably also want to remove ``'django.core.context_processors.i18n'`` |
43 | | from your ``TEMPLATE_CONTEXT_PROCESSORS`` setting. |
| 43 | from your :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting. |
44 | 44 | |
45 | 45 | If you do need internationalization: three steps |
46 | 46 | ================================================ |
… |
… |
|
293 | 293 | |
294 | 294 | Each ``RequestContext`` has access to three translation-specific variables: |
295 | 295 | |
296 | | * ``LANGUAGES`` is a list of tuples in which the first element is the |
| 296 | * :setting:`LANGUAGES` is a list of tuples in which the first element is the |
297 | 297 | language code and the second is the language name (translated into the |
298 | 298 | currently active locale). |
299 | 299 | |
… |
… |
|
368 | 368 | The allow_lazy() decorator |
369 | 369 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
370 | 370 | |
371 | | Django offers many utility functions (particularly in ``django.utils``) that |
| 371 | Django offers many utility functions (particularly in :mod:`django.utils`) that |
372 | 372 | take a string as their first argument and do something to that string. These |
373 | 373 | functions are used by template filters as well as directly in other code. |
374 | 374 | |
… |
… |
|
592 | 592 | selection based on data from the request. It customizes content for each user. |
593 | 593 | |
594 | 594 | To use ``LocaleMiddleware``, add ``'django.middleware.locale.LocaleMiddleware'`` |
595 | | to your ``MIDDLEWARE_CLASSES`` setting. Because middleware order matters, you |
| 595 | to your :setting:`MIDDLEWARE_CLASSES` setting. Because middleware order matters, you |
596 | 596 | should follow these guidelines: |
597 | 597 | |
598 | 598 | * Make sure it's one of the first middlewares installed. |
… |
… |
|
600 | 600 | makes use of session data. |
601 | 601 | * If you use ``CacheMiddleware``, put ``LocaleMiddleware`` after it. |
602 | 602 | |
603 | | For example, your ``MIDDLEWARE_CLASSES`` might look like this:: |
| 603 | For example, your :setting:`MIDDLEWARE_CLASSES` might look like this:: |
604 | 604 | |
605 | 605 | MIDDLEWARE_CLASSES = ( |
606 | 606 | 'django.contrib.sessions.middleware.SessionMiddleware', |
… |
… |
|
623 | 623 | |
624 | 624 | In Django version 0.96 and before, the cookie's name is hard-coded to |
625 | 625 | ``django_language``. In Django 1,0, The cookie name is set by the |
626 | | ``LANGUAGE_COOKIE_NAME`` setting. (The default name is |
| 626 | :setting:`LANGUAGE_COOKIE_NAME` setting. (The default name is |
627 | 627 | ``django_language``.) |
628 | 628 | |
629 | 629 | * Failing that, it looks at the ``Accept-Language`` HTTP header. This |
… |
… |
|
631 | 631 | prefer, in order by priority. Django tries each language in the header |
632 | 632 | until it finds one with available translations. |
633 | 633 | |
634 | | * Failing that, it uses the global ``LANGUAGE_CODE`` setting. |
| 634 | * Failing that, it uses the global :setting:`LANGUAGE_CODE` setting. |
635 | 635 | |
636 | 636 | .. _locale-middleware-notes: |
637 | 637 | |
… |
… |
|
649 | 649 | * Only languages listed in the :setting:`LANGUAGES` setting can be selected. |
650 | 650 | If you want to restrict the language selection to a subset of provided |
651 | 651 | languages (because your application doesn't provide all those languages), |
652 | | set ``LANGUAGES`` to a list of languages. For example:: |
| 652 | set :setting:`LANGUAGES` to a list of languages. For example:: |
653 | 653 | |
654 | 654 | LANGUAGES = ( |
655 | 655 | ('de', _('German')), |
… |
… |
|
662 | 662 | |
663 | 663 | .. _LANGUAGES setting: ../settings/#languages |
664 | 664 | |
665 | | * If you define a custom ``LANGUAGES`` setting, as explained in the |
| 665 | * If you define a custom :setting:`LANGUAGES` setting, as explained in the |
666 | 666 | previous bullet, it's OK to mark the languages as translation strings |
667 | 667 | -- but use a "dummy" ``ugettext()`` function, not the one in |
668 | | ``django.utils.translation``. You should *never* import |
669 | | ``django.utils.translation`` from within your settings file, because that |
| 668 | :mod:`django.utils.translation`. You should *never* import |
| 669 | :mod:`django.utils.translation` from within your settings file, because that |
670 | 670 | module in itself depends on the settings, and that would cause a circular |
671 | 671 | import. |
672 | 672 | |
… |
… |
|
683 | 683 | With this arrangement, ``django-admin.py makemessages`` will still find |
684 | 684 | and mark these strings for translation, but the translation won't happen |
685 | 685 | at runtime -- so you'll have to remember to wrap the languages in the |
686 | | *real* ``ugettext()`` in any code that uses ``LANGUAGES`` at runtime. |
| 686 | *real* ``ugettext()`` in any code that uses :setting:`LANGUAGES` at runtime. |
687 | 687 | |
688 | 688 | * The ``LocaleMiddleware`` can only select languages for which there is a |
689 | 689 | Django-provided base translation. If you want to provide translations |
… |
… |
|
700 | 700 | Technical message IDs are easily recognized; they're all upper case. You |
701 | 701 | don't translate the message ID as with other messages, you provide the |
702 | 702 | correct local variant on the provided English value. For example, with |
703 | | ``DATETIME_FORMAT`` (or ``DATE_FORMAT`` or ``TIME_FORMAT``), this would |
| 703 | :setting:`DATETIME_FORMAT` (or :setting:`DATE_FORMAT` or :setting:`TIME_FORMAT`), this would |
704 | 704 | be the format string that you want to use in your language. The format |
705 | 705 | is identical to the format strings used by the ``now`` template tag. |
706 | 706 | |
… |
… |
|
716 | 716 | return HttpResponse("You prefer to read another language.") |
717 | 717 | |
718 | 718 | Note that, with static (middleware-less) translation, the language is in |
719 | | ``settings.LANGUAGE_CODE``, while with dynamic (middleware) translation, it's |
| 719 | :setting:`settings.LANGUAGE_CODE<LANGUAGE_CODE>`, while with dynamic (middleware) translation, it's |
720 | 720 | in ``request.LANGUAGE_CODE``. |
721 | 721 | |
722 | 722 | .. _settings file: ../settings/ |
… |
… |
|
757 | 757 | |
758 | 758 | * ``$APPPATH/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
759 | 759 | * ``$PROJECTPATH/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
760 | | * All paths listed in ``LOCALE_PATHS`` in your settings file are |
| 760 | * All paths listed in :setting:`LOCALE_PATHS` in your settings file are |
761 | 761 | searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)`` |
762 | 762 | * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
763 | 763 | |
… |
… |
|
769 | 769 | to produce the binary ``django.mo`` files that are used by ``gettext``. |
770 | 770 | |
771 | 771 | You can also run ``django-admin.py compilemessages --settings=path.to.settings`` |
772 | | to make the compiler process all the directories in your ``LOCALE_PATHS`` |
| 772 | to make the compiler process all the directories in your :setting:`LOCALE_PATHS` |
773 | 773 | setting. |
774 | 774 | |
775 | 775 | Application message files are a bit complicated to discover -- they need the |
… |
… |
|
806 | 806 | parameter set in request. If session support is enabled, the view |
807 | 807 | saves the language choice in the user's session. Otherwise, it saves the |
808 | 808 | language choice in a cookie that is by default named ``django_language``. |
809 | | (The name can be changed through the ``LANGUAGE_COOKIE_NAME`` setting.) |
| 809 | (The name can be changed through the :setting:`LANGUAGE_COOKIE_NAME` setting.) |
810 | 810 | |
811 | 811 | After setting the language choice, Django redirects the user, following this |
812 | 812 | algorithm: |
… |
… |
|
868 | 868 | ) |
869 | 869 | |
870 | 870 | Each string in ``packages`` should be in Python dotted-package syntax (the |
871 | | same format as the strings in ``INSTALLED_APPS``) and should refer to a package |
| 871 | same format as the strings in :setting:`INSTALLED_APPS`) and should refer to a package |
872 | 872 | that contains a ``locale`` directory. If you specify multiple packages, all |
873 | 873 | those catalogs are merged into one catalog. This is useful if you have |
874 | 874 | JavaScript that uses strings from different applications. |
… |
… |
|
883 | 883 | signs in the URL. This is especially useful if your pages use code from |
884 | 884 | different apps and this changes often and you don't want to pull in one big |
885 | 885 | catalog file. As a security measure, these values can only be either |
886 | | ``django.conf`` or any package from the ``INSTALLED_APPS`` setting. |
| 886 | ``django.conf`` or any package from the :setting:`INSTALLED_APPS` setting. |
887 | 887 | |
888 | 888 | Using the JavaScript translation catalog |
889 | 889 | ---------------------------------------- |
… |
… |
|
995 | 995 | * Add ``;C:\Program Files\gettext-utils\bin`` at the end of the |
996 | 996 | ``Variable value`` field |
997 | 997 | |
998 | | You may also use ``gettext`` binaries you have obtained elsewhere, so long as |
| 998 | You may also use ``gettext`` binaries you have obtained elsewhere, so long as |
999 | 999 | the ``xgettext --version`` command works properly. Some version 0.14.4 binaries |
1000 | | have been found to not support this command. Do not attempt to use Django |
| 1000 | have been found to not support this command. Do not attempt to use Django |
1001 | 1001 | translation utilities with a ``gettext`` package if the command ``xgettext |
1002 | 1002 | --version`` entered at a Windows command prompt causes a popup window saying |
1003 | 1003 | "xgettext.exe has generated errors and will be closed by Windows". |
-
diff --git a/docs/topics/templates.txt b/docs/topics/templates.txt
a
|
b
|
|
99 | 99 | ``title`` attribute of the ``section`` object. |
100 | 100 | |
101 | 101 | If you use a variable that doesn't exist, the template system will insert |
102 | | the value of the ``TEMPLATE_STRING_IF_INVALID`` setting, which is set to ``''`` |
| 102 | the value of the :setting:`TEMPLATE_STRING_IF_INVALID` setting, which is set to ``''`` |
103 | 103 | (the empty string) by default. |
104 | 104 | |
105 | 105 | See `Using the built-in reference`_, below, for help on finding what variables |
-
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
a
|
b
|
|
416 | 416 | Overview and a quick example |
417 | 417 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
418 | 418 | |
419 | | To use the test client, instantiate ``django.test.client.Client`` and retrieve |
| 419 | To use the test client, instantiate :class:`django.test.client.Client` and retrieve |
420 | 420 | Web pages:: |
421 | 421 | |
422 | 422 | >>> from django.test.client import Client |
… |
… |
|
470 | 470 | Making requests |
471 | 471 | ~~~~~~~~~~~~~~~ |
472 | 472 | |
473 | | Use the ``django.test.client.Client`` class to make requests. It requires no |
| 473 | Use the :class:`django.test.client.Client` class to make requests. It requires no |
474 | 474 | arguments at time of construction: |
475 | 475 | |
476 | 476 | .. class:: Client() |
… |
… |
|
781 | 781 | |
782 | 782 | Converting a normal ``unittest.TestCase`` to a Django ``TestCase`` is easy: |
783 | 783 | just change the base class of your test from ``unittest.TestCase`` to |
784 | | ``django.test.TestCase``. All of the standard Python unit test functionality |
| 784 | :class:`django.test.TestCase`. All of the standard Python unit test functionality |
785 | 785 | will continue to be available, but it will be augmented with some useful |
786 | 786 | additions. |
787 | 787 | |
… |
… |
|
792 | 792 | |
793 | 793 | .. attribute:: TestCase.client |
794 | 794 | |
795 | | Every test case in a ``django.test.TestCase`` instance has access to an |
| 795 | Every test case in a :class:`django.test.TestCase` instance has access to an |
796 | 796 | instance of a Django test client. This client can be accessed as |
797 | 797 | ``self.client``. This client is recreated for each test, so you don't have to |
798 | 798 | worry about state (such as cookies) carrying over from one test to another. |
… |
… |
|
857 | 857 | |
858 | 858 | Once you've created a fixture and placed it somewhere in your Django project, |
859 | 859 | you can use it in your unit tests by specifying a ``fixtures`` class attribute |
860 | | on your ``django.test.TestCase`` subclass:: |
| 860 | on your :class:`django.test.TestCase` subclass:: |
861 | 861 | |
862 | 862 | from django.test import TestCase |
863 | 863 | from myapp.models import Animal |
… |
… |
|
900 | 900 | particular URL. |
901 | 901 | |
902 | 902 | In order to provide a reliable URL space for your test, |
903 | | ``django.test.TestCase`` provides the ability to customize the URLconf |
| 903 | :class:`django.test.TestCase` provides the ability to customize the URLconf |
904 | 904 | configuration for the duration of the execution of a test suite. If your |
905 | 905 | ``TestCase`` instance defines an ``urls`` attribute, the ``TestCase`` will use |
906 | | the value of that attribute as the ``ROOT_URLCONF`` for the duration of that |
| 906 | the value of that attribute as the :setting:`ROOT_URLCONF` for the duration of that |
907 | 907 | test. |
908 | 908 | |
909 | 909 | For example:: |
… |
… |
|
1128 | 1128 | :synopsis: Helpers to write custom test runners. |
1129 | 1129 | |
1130 | 1130 | To assist in the creation of your own test runner, Django provides a number of |
1131 | | utility methods in the ``django.test.utils`` module. |
| 1131 | utility methods in the :mod:`django.test.utils` module. |
1132 | 1132 | |
1133 | 1133 | .. function:: setup_test_environment() |
1134 | 1134 | |
… |
… |
|
1163 | 1163 | Returns the name of the test database that it created. |
1164 | 1164 | |
1165 | 1165 | ``create_test_db()`` has the side effect of modifying |
1166 | | ``settings.DATABASE_NAME`` to match the name of the test database. |
| 1166 | :setting:`settings.DATABASE_NAME<DATABASE_NAME>` to match the name of the test database. |
1167 | 1167 | |
1168 | 1168 | .. versionchanged:: 1.0 |
1169 | 1169 | ``create_test_db()`` now returns the name of the test database. |