-
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 |
65 | | are fewer than two related objects. |
| 64 | Django won't bother displaying the filter for a :class:`ManyToManyField` if |
| 65 | there are fewer than two related objects. |
66 | 66 | |
67 | 67 | For example, if your ``list_filter`` includes ``sites``, and there's only one |
68 | 68 | site in your database, it won't display a "Site" filter. In that case, |
-
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 |
18 | | of dictionaries in order of query execution. Each dictionary has the following:: |
| 17 | :data:`connection.queries` is only available if :setting:`DEBUG` is ``True``. |
| 18 | It's a list of dictionaries in order of query execution. Each dictionary has |
| 19 | the following:: |
19 | 20 | |
20 | 21 | ``sql`` -- The raw SQL statement |
21 | 22 | ``time`` -- How long the statement took to execute, in seconds. |
22 | 23 | |
23 | | ``connection.queries`` includes all SQL statements -- INSERTs, UPDATES, |
| 24 | :data:`connection.queries` includes all SQL statements -- INSERTs, UPDATES, |
24 | 25 | SELECTs, etc. Each time your app hits the database, the query will be recorded. |
25 | 26 | |
26 | 27 | Can I use Django with a pre-existing database? |
… |
… |
|
79 | 80 | |
80 | 81 | Django isn't known to leak memory. If you find your Django processes are |
81 | 82 | 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 |
83 | | Django saves a copy of every SQL statement it has executed. |
| 83 | sure your :setting:`DEBUG` setting is set to ``False``. If ``DEBUG`` is |
| 84 | ``True``, then Django saves a copy of every SQL statement it has executed. |
84 | 85 | |
85 | | (The queries are saved in ``django.db.connection.queries``. See |
| 86 | (The queries are saved in :data:`django.db.connection.queries`. See |
86 | 87 | `How can I see the raw SQL queries Django is running?`_.) |
87 | 88 | |
88 | | To fix the problem, set ``DEBUG`` to ``False``. |
| 89 | To fix the problem, set :setting:`DEBUG` to ``False``. |
89 | 90 | |
90 | 91 | If you need to clear the query list manually at any point in your functions, |
91 | | just call ``reset_queries()``, like this:: |
| 92 | just call :func:`reset_queries`, like this:: |
92 | 93 | |
93 | 94 | from django import db |
94 | 95 | db.reset_queries() |
-
diff --git a/docs/howto/custom-file-storage.txt b/docs/howto/custom-file-storage.txt
a
|
b
|
|
53 | 53 | |
54 | 54 | **Required**. |
55 | 55 | |
56 | | Called by ``Storage.open()``, this is the actual mechanism the storage class |
| 56 | Called by :meth:`Storage.open`, this is the actual mechanism the storage class |
57 | 57 | uses to open the file. This must return a ``File`` object, though in most cases, |
58 | 58 | you'll want to return some subclass here that implements logic specific to the |
59 | 59 | backend storage system. |
… |
… |
|
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 |
| 66 | be a :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 |
77 | | and underscores from the original filename, removing everything else. |
| 76 | The code provided on :class:`Storage` retains only alpha-numeric characters, |
| 77 | periods and underscores from the original filename, removing everything else.n |
78 | 78 | |
79 | 79 | ``get_available_name(name)`` |
80 | 80 | ---------------------------- |
… |
… |
|
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 | ------------------ |
… |
… |
|
45 | 45 | self.east = east |
46 | 46 | self.south = south |
47 | 47 | self.west = west |
48 | | |
| 48 | |
49 | 49 | # ... (other possibly useful methods omitted) ... |
50 | 50 | |
51 | 51 | .. _Bridge: http://en.wikipedia.org/wiki/Contract_bridge |
… |
… |
|
203 | 203 | :class:`ForeignKey`). For advanced use only. |
204 | 204 | * :attr:`~django.db.models.Field.default` |
205 | 205 | * :attr:`~django.db.models.Field.editable` |
206 | | * :attr:`~django.db.models.Field.serialize`: If ``False``, the field will |
| 206 | * :attr:`~django.db.models.Field.serialize`: If ``False``, the field will |
207 | 207 | not be serialized when the model is passed to Django's :ref:`serializers |
208 | 208 | <topics-serialization>`. Defaults to ``True``. |
209 | 209 | * :attr:`~django.db.models.Field.prepopulate_from` |
… |
… |
|
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 |
292 | | import the Django settings module and check the :setting:`DATABASE_ENGINE` setting. |
293 | | For example:: |
| 291 | ``datetime``. The simplest way to handle this in a :meth:`db_type` method is to |
| 292 | import the Django settings module and check the :setting:`DATABASE_ENGINE` |
| 293 | setting. For example:: |
294 | 294 | |
295 | 295 | class MyDateField(models.Field): |
296 | 296 | def db_type(self): |
… |
… |
|
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 |
422 | | shouldn't need to implement this method unless your custom field need a special |
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``). |
| 421 | database. As the default implementation just calls :meth:`get_db_prep_value`, |
| 422 | you shouldn't need to implement this method unless your custom field need a |
| 423 | special conversion when being saved that is not the same as the used for normal |
| 424 | query 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`, |
| 457 | :lookup:`icontains`, :lookup:`gt`, :lookup:`gte`, :lookup:`lt`, :lookup:`lte`, |
| 458 | :lookup:`in`, :lookup:`startswith`, :lookup:`istartswith`, :lookup:`endswith`, |
| 459 | :lookup:`iendswith`, :lookup:`range`, :lookup:`year`, :lookup:`month`, |
| 460 | :lookup:`day`, :lookup:`isnull`, :lookup:`search`, :lookup:`regex`, and |
| 461 | :lookup:`iregex`. |
460 | 462 | |
461 | 463 | 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 |
463 | | list when you were expecting an object, for example) or a ``TypeError`` if |
| 464 | should raise either a :exc:`ValueError` if the ``value`` is of the wrong sort |
| 465 | (a list when you were expecting an object, for example) or a ``TypeError`` if |
464 | 466 | your field does not support that type of lookup. For many fields, you can get |
465 | 467 | by with handling the lookup types that need special handling for your field |
466 | 468 | and pass the rest of the :meth:`get_db_prep_lookup` method of the parent class. |
467 | 469 | |
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. |
| 470 | If you needed to implement :meth:`get_db_prep_save`, you will usually need to |
| 471 | implement :meth:`get_db_prep_lookup`. If you don't, :meth:`get_db_prep_value` |
| 472 | will be called by the default implementation, to manage :lookup:`exact`, |
| 473 | :lookup:`gt`, :lookup:`gte`, :lookup:`lt`, :lookup:`lte`, :lookup:`in` and |
| 474 | :lookup:`range` lookups. |
472 | 475 | |
473 | 476 | You may also want to implement this method to limit the lookup types that could |
474 | 477 | be used with your custom field type. |
475 | 478 | |
476 | | Note that, for ``range`` and ``in`` lookups, ``get_db_prep_lookup`` will receive |
477 | | a list of objects (presumably of the right type) and will need to convert them |
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 |
480 | | pieces. |
| 479 | Note that, for :lookup:`range` and :lookup:`in` lookups, |
| 480 | :meth:`get_db_prep_lookup` will receive a list of objects (presumably of the |
| 481 | right type) and will need to convert them to a list of things of the right type |
| 482 | for passing to the database. Most of the time, you can reuse |
| 483 | :meth:`get_db_prep_value`, or at least factor out some common pieces. |
481 | 484 | |
482 | | For example, the following code implements ``get_db_prep_lookup`` to limit the |
483 | | accepted lookup types to ``exact`` and ``in``:: |
| 485 | For example, the following code implements :meth:`get_db_prep_lookup` to limit |
| 486 | the accepted lookup types to :lookup:`exact` and ``in``:: |
484 | 487 | |
485 | 488 | class HandField(models.Field): |
486 | 489 | # ... |
… |
… |
|
608 | 611 | |
609 | 612 | In addition to the above methods, fields that deal with files have a few other |
610 | 613 | special requirements which must be taken into account. The majority of the |
611 | | mechanics provided by ``FileField``, such as controlling database storage and |
612 | | retrieval, can remain unchanged, leaving subclasses to deal with the challenge |
613 | | of supporting a particular type of file. |
| 614 | mechanics provided by :class:`FileField`, such as controlling database storage |
| 615 | and retrieval, can remain unchanged, leaving subclasses to deal with the |
| 616 | challenge of supporting a particular type of file. |
614 | 617 | |
615 | | Django provides a ``File`` class, which is used as a proxy to the file's |
| 618 | Django provides a :class:`File` class, which is used as a proxy to the file's |
616 | 619 | contents and operations. This can be subclassed to customize how the file is |
617 | 620 | accessed, and what methods are available. It lives at |
618 | | ``django.db.models.fields.files``, and its default behavior is explained in the |
619 | | :ref:`file documentation <ref-files-file>`. |
| 621 | :mod:`django.db.models.fields.files`, and its default behavior is explained in |
| 622 | the :ref:`file documentation <ref-files-file>`. |
620 | 623 | |
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. |
| 624 | Once a subclass of :class:`File` is created, the new :class:`FileField` |
| 625 | subclass must be told to use it. To do so, simply assign the new :class:`File` |
| 626 | subclass to the special :attr:`attr_class` attribute of the ``FileField`` |
| 627 | subclass. |
624 | 628 | |
625 | 629 | A few suggestions |
626 | 630 | ------------------ |
… |
… |
|
628 | 632 | In addition to the above details, there are a few guidelines which can greatly |
629 | 633 | improve the efficiency and readability of the field's code. |
630 | 634 | |
631 | | 1. The source for Django's own ``ImageField`` (in |
| 635 | 1. The source for Django's own :class:`ImageField` (in |
632 | 636 | ``django/db/models/fields/files.py``) is a great example of how to |
633 | 637 | subclass ``FileField`` to support a particular type of file, as it |
634 | 638 | 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 |
61 | | tags and filters are registered. So, near the top of your module, put the |
| 60 | named ``register`` that is a :class:`template.Library` instance, in which all |
| 61 | the tags and filters are registered. So, near the top of your module, put the |
62 | 62 | following:: |
63 | 63 | |
64 | 64 | from django import template |
… |
… |
|
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 templatei |
| 131 | language:: |
131 | 132 | |
132 | 133 | register.filter('cut', cut) |
133 | 134 | register.filter('lower', lower) |
134 | 135 | |
135 | | The ``Library.filter()`` method takes two arguments: |
| 136 | The :meth:`Library.filter` method takes two arguments: |
136 | 137 | |
137 | 138 | 1. The name of the filter -- a string. |
138 | 139 | 2. The compilation function -- a Python function (not the name of the |
139 | 140 | function as a string). |
140 | 141 | |
141 | | If you're using Python 2.4 or above, you can use ``register.filter()`` as a |
| 142 | If you're using Python 2.4 or above, you can use :func:`register.filter` as a |
142 | 143 | decorator instead:: |
143 | 144 | |
144 | 145 | @register.filter(name='cut') |
… |
… |
|
172 | 173 | They're commonly used for output that contains raw HTML that is intended |
173 | 174 | to be interpreted as-is on the client side. |
174 | 175 | |
175 | | Internally, these strings are of type ``SafeString`` or ``SafeUnicode``. |
176 | | They share a common base class of ``SafeData``, so you can test |
177 | | for them using code like:: |
| 176 | Internally, these strings are of type :class:`SafeString` ori |
| 177 | :class:`SafeUnicode`. They share a common base class of |
| 178 | :class:`SafeData`, so you can test for them using code like:: |
178 | 179 | |
179 | 180 | if isinstance(value, SafeData): |
180 | 181 | # Do something with the "safe" string. |
… |
… |
|
184 | 185 | These strings are only escaped once, however, even if auto-escaping |
185 | 186 | applies. |
186 | 187 | |
187 | | Internally, these strings are of type ``EscapeString`` or |
188 | | ``EscapeUnicode``. Generally you don't have to worry about these; they |
189 | | exist for the implementation of the ``escape`` filter. |
| 188 | Internally, these strings are of type :class:`EscapeString` or |
| 189 | :class:`EscapeUnicode`. Generally you don't have to worry about these; |
| 190 | they exist for the implementation of the ``escape`` filter. |
190 | 191 | |
191 | 192 | Template filter code falls into one of two situations: |
192 | 193 | |
… |
… |
|
209 | 210 | introduce any possibility of unsafe HTML." |
210 | 211 | |
211 | 212 | The reason ``is_safe`` is necessary is because there are plenty of |
212 | | normal string operations that will turn a ``SafeData`` object back into |
213 | | a normal ``str`` or ``unicode`` object and, rather than try to catch |
214 | | them all, which would be very difficult, Django repairs the damage after |
215 | | the filter has completed. |
| 213 | normal string operations that will turn a :class:`SafeData` object back |
| 214 | into a normal ``str`` or ``unicode`` object and, rather than try to |
| 215 | catch tem all, which would be very difficult, Django repairs the damage |
| 216 | after the filter has completed. |
216 | 217 | |
217 | 218 | For example, suppose you have a filter that adds the string ``xx`` to the |
218 | 219 | end of any input. Since this introduces no dangerous HTML characters to |
… |
… |
|
289 | 290 | ``autoescape`` keyword argument mean that our function will know whether |
290 | 291 | automatic escaping is in effect when the filter is called. We use |
291 | 292 | ``autoescape`` to decide whether the input data needs to be passed |
292 | | through ``django.utils.html.conditional_escape`` or not. (In the latter |
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`` |
296 | | instance is passed to ``conditional_escape()``, the data is returned |
297 | | unchanged. |
| 293 | through :func:`django.utils.html.conditional_escape` or not. (In the |
| 294 | latter case, we just use the identity function as the "escape" |
| 295 | function.) The :func:`conditional_escape` function is like |
| 296 | :func:`escape` except it only escapes input that is **not** a |
| 297 | :class:`SafeData` instance. If a ``SafeData`` instance is passed to |
| 298 | ``conditional_escape()``, the data is returned unchanged. |
298 | 299 | |
299 | 300 | Finally, in the above example, we remember to mark the result as safe |
300 | 301 | so that our HTML is inserted directly into the template without further |
… |
… |
|
318 | 319 | how the compilation works and how the rendering works. |
319 | 320 | |
320 | 321 | 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`` |
| 322 | ''nodes''. Each node is an instance of :class:`django.template.Node` and has |
| 323 | a ``render()`` method. A compiled template is, simply, a list of :class:`Node` |
323 | 324 | objects. When you call ``render()`` on a compiled template object, the template |
324 | 325 | calls ``render()`` on each ``Node`` in its node list, with the given context. |
325 | 326 | The results are all concatenated together to form the output of the template. |
… |
… |
|
346 | 347 | |
347 | 348 | .. _`strftime syntax`: http://docs.python.org/library/time.html#time.strftime |
348 | 349 | |
349 | | The parser for this function should grab the parameter and create a ``Node`` |
350 | | object:: |
| 350 | The parser for this function should grab the parameter and create a |
| 351 | :class:`Node` object:: |
351 | 352 | |
352 | 353 | from django import template |
353 | 354 | def do_current_time(parser, token): |
… |
… |
|
368 | 369 | * ``token.contents`` is a string of the raw contents of the tag. In our |
369 | 370 | example, it's ``'current_time "%Y-%m-%d %I:%M %p"'``. |
370 | 371 | |
371 | | * The ``token.split_contents()`` method separates the arguments on spaces |
| 372 | * The :meth:`token.split_contents` method separates the arguments on spaces |
372 | 373 | while keeping quoted strings together. The more straightforward |
373 | | ``token.contents.split()`` wouldn't be as robust, as it would naively |
| 374 | :func:`token.contents.split` wouldn't be as robust, as it would naively |
374 | 375 | split on *all* spaces, including those within quoted strings. It's a good |
375 | | idea to always use ``token.split_contents()``. |
| 376 | idea to always use :meth:`token.split_contents`. |
376 | 377 | |
377 | 378 | * This function is responsible for raising |
378 | | ``django.template.TemplateSyntaxError``, with helpful messages, for |
| 379 | :exc:`django.template.TemplateSyntaxError`, with helpful messages, for |
379 | 380 | any syntax error. |
380 | 381 | |
381 | | * The ``TemplateSyntaxError`` exceptions use the ``tag_name`` variable. |
| 382 | * The :exc:`TemplateSyntaxError` exceptions use the ``tag_name`` variable. |
382 | 383 | Don't hard-code the tag's name in your error messages, because that |
383 | 384 | couples the tag's name to your function. ``token.contents.split()[0]`` |
384 | 385 | will ''always'' be the name of your tag -- even when the tag has no |
… |
… |
|
397 | 398 | Writing the renderer |
398 | 399 | ~~~~~~~~~~~~~~~~~~~~ |
399 | 400 | |
400 | | The second step in writing custom tags is to define a ``Node`` subclass that |
401 | | has a ``render()`` method. |
| 401 | The second step in writing custom tags is to define a :class:`Node` subclass |
| 402 | that has a :meth:`render` method. |
402 | 403 | |
403 | 404 | Continuing the above example, we need to define ``CurrentTimeNode``:: |
404 | 405 | |
… |
… |
|
443 | 444 | |
444 | 445 | Also, if your template tag creates a new context for performing some |
445 | 446 | 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 |
| 447 | The ``__init__`` method for the :class:`Context` class takes a parameter called |
447 | 448 | ``autoescape`` that you can use for this purpose. For example:: |
448 | 449 | |
449 | 450 | def render(self, context): |
… |
… |
|
466 | 467 | Registering the tag |
467 | 468 | ~~~~~~~~~~~~~~~~~~~ |
468 | 469 | |
469 | | Finally, register the tag with your module's ``Library`` instance, as explained |
470 | | in "Writing custom template filters" above. Example:: |
| 470 | Finally, register the tag with your module's :class:`Library` instance, as |
| 471 | explained in "Writing custom template filters" above. Example:: |
471 | 472 | |
472 | 473 | register.tag('current_time', do_current_time) |
473 | 474 | |
… |
… |
|
496 | 497 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
497 | 498 | |
498 | 499 | Although you can pass any number of arguments to a template tag using |
499 | | ``token.split_contents()``, the arguments are all unpacked as |
| 500 | :meth:`token.split_contents`, the arguments are all unpacked as |
500 | 501 | string literals. A little more work is required in order to pass dynamic |
501 | 502 | content (a template variable) to a template tag as an argument. |
502 | 503 | |
503 | 504 | 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 |
505 | | object and have the template tag format that date-time: |
| 505 | returned the string, suppose you wanted to pass in a :class:`DateTimeField` |
| 506 | from an object and have the template tag format that date-time: |
506 | 507 | |
507 | 508 | .. code-block:: html+django |
508 | 509 | |
509 | 510 | <p>This post was last updated at {% format_time blog_entry.date_updated "%Y-%m-%d %I:%M %p" %}.</p> |
510 | 511 | |
511 | | Initially, ``token.split_contents()`` will return three values: |
| 512 | Initially, :meth:`token.split_contents` will return three values: |
512 | 513 | |
513 | 514 | 1. The tag name ``format_time``. |
514 | 515 | 2. The string "blog_entry.date_updated" (without the surrounding quotes). |
… |
… |
|
531 | 532 | |
532 | 533 | .. versionchanged:: 1.0 |
533 | 534 | 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. |
| 535 | has been deprecated in favor of a new :class:`template.Variable` class. |
535 | 536 | |
536 | 537 | You also have to change the renderer to retrieve the actual contents of the |
537 | 538 | ``date_updated`` property of the ``blog_entry`` object. This can be |
538 | | accomplished by using the ``Variable()`` class in ``django.template``. |
| 539 | accomplished by using the :class:`Variable` class in :mod:`django.template`. |
539 | 540 | |
540 | | To use the ``Variable`` class, simply instantiate it with the name of the |
| 541 | To use the :class:`Variable` class, simply instantiate it with the name of the |
541 | 542 | variable to be resolved, and then call ``variable.resolve(context)``. So, |
542 | 543 | for example:: |
543 | 544 | |
… |
… |
|
553 | 554 | except template.VariableDoesNotExist: |
554 | 555 | return '' |
555 | 556 | |
556 | | Variable resolution will throw a ``VariableDoesNotExist`` exception if it cannot |
557 | | resolve the string passed to it in the current context of the page. |
| 557 | Variable resolution will throw a :exc:`VariableDoesNotExist` exception if it |
| 558 | cannot resolve the string passed to it in the current context of the page. |
558 | 559 | |
559 | 560 | Shortcut for simple tags |
560 | 561 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
561 | 562 | |
562 | | Many template tags take a number of arguments -- strings or a template variables |
563 | | -- and return a string after doing some processing based solely on |
| 563 | Many template tags take a number of arguments -- strings or a template |
| 564 | variables -- and return a string after doing some processing based solely on |
564 | 565 | the input argument and some external information. For example, the |
565 | 566 | ``current_time`` tag we wrote above is of this variety: we give it a format |
566 | 567 | string, it returns the time as a string. |
567 | 568 | |
568 | 569 | To ease the creation of the types of tags, Django provides a helper function, |
569 | 570 | ``simple_tag``. This function, which is a method of |
570 | | ``django.template.Library``, takes a function that accepts any number of |
| 571 | :class:`django.template.Library`, takes a function that accepts any number of |
571 | 572 | arguments, wraps it in a ``render`` function and the other necessary bits |
572 | 573 | mentioned above and registers it with the template system. |
573 | 574 | |
… |
… |
|
605 | 606 | Another common type of template tag is the type that displays some data by |
606 | 607 | rendering *another* template. For example, Django's admin interface uses custom |
607 | 608 | template tags to display the buttons along the bottom of the "add/change" form |
608 | | pages. Those buttons always look the same, but the link targets change depending |
609 | | on the object being edited -- so they're a perfect case for using a small |
610 | | template that is filled with details from the current object. (In the admin's |
611 | | case, this is the ``submit_row`` tag.) |
| 609 | pages. Those buttons always look the same, but the link targets change |
| 610 | depending on the object being edited -- so they're a perfect case for using a |
| 611 | small template that is filled with details from the current object. (In the |
| 612 | admin's case, this is the ``submit_row`` tag.) |
612 | 613 | |
613 | 614 | These sorts of tags are called "inclusion tags". |
614 | 615 | |
… |
… |
|
652 | 653 | </ul> |
653 | 654 | |
654 | 655 | 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 |
656 | | in a file called ``results.html`` in a directory that's searched by the template |
657 | | loader, we'd register the tag like this:: |
| 656 | method on a :class:`Library` object. Following our example, if the above |
| 657 | template is in a file called ``results.html`` in a directory that's searched by |
| 658 | the template loader, we'd register the tag like this:: |
658 | 659 | |
659 | 660 | # Here, register is a django.template.Library instance, as before |
660 | 661 | register.inclusion_tag('results.html')(show_results) |
… |
… |
|
690 | 691 | |
691 | 692 | (Note that the first parameter to the function *must* be called ``context``.) |
692 | 693 | |
693 | | In that ``register.inclusion_tag()`` line, we specified ``takes_context=True`` |
694 | | and the name of the template. Here's what the template ``link.html`` might look |
695 | | like: |
| 694 | In that :func:`register.inclusion_tag` line, we specified |
| 695 | ``takes_context=True`` and the name of the template. Here's what the template |
| 696 | ``link.html`` might look like: |
696 | 697 | |
697 | 698 | .. code-block:: html+django |
698 | 699 | |
… |
… |
|
802 | 803 | return '' |
803 | 804 | |
804 | 805 | ``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 |
| 806 | returns an instance of :class:`django.template.NodeList`, which is a list of |
| 807 | all :class:`Node` objects that the parser encountered ''before'' it encountered |
807 | 808 | any of the tags named in the tuple. |
808 | 809 | |
809 | 810 | In ``"nodelist = parser.parse(('endcomment',))"`` in the above example, |
… |
… |
|
813 | 814 | |
814 | 815 | After ``parser.parse()`` is called, the parser hasn't yet "consumed" the |
815 | 816 | ``{% endcomment %}`` tag, so the code needs to explicitly call |
816 | | ``parser.delete_first_token()``. |
| 817 | :func:`parser.delete_first_token`. |
817 | 818 | |
818 | 819 | ``CommentNode.render()`` simply returns an empty string. Anything between |
819 | 820 | ``{% 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
|
|
42 | 42 | create a ``mysite`` directory in your current directory. |
43 | 43 | |
44 | 44 | .. admonition:: Mac OS X permissions |
45 | | |
| 45 | |
46 | 46 | If you're using Mac OS X, you may see the message "permission denied" when |
47 | 47 | you try to run ``django-admin.py startproject``. This is because, on |
48 | 48 | Unix-based systems like OS X, a file must be marked as "executable" before it |
49 | 49 | can be run as a program. To do this, open Terminal.app and navigate (using |
50 | 50 | the ``cd`` command) to the directory where :ref:`django-admin.py |
51 | | <ref-django-admin>` is installed, then run the command |
| 51 | <ref-django-admin>` is installed, then run the command |
52 | 52 | ``chmod +x django-admin.py``. |
53 | 53 | |
54 | 54 | .. note:: |
… |
… |
|
90 | 90 | * :file:`__init__.py`: An empty file that tells Python that this directory |
91 | 91 | should be considered a Python package. (Read `more about packages`_ in the |
92 | 92 | official Python docs if you're a Python beginner.) |
93 | | |
| 93 | |
94 | 94 | * :file:`manage.py`: A command-line utility that lets you interact with this |
95 | 95 | Django project in various ways. You can read all the details about |
96 | 96 | :file:`manage.py` in :ref:`ref-django-admin`. |
97 | | |
| 97 | |
98 | 98 | * :file:`settings.py`: Settings/configuration for this Django project. |
99 | 99 | :ref:`topics-settings` will tell you all about how settings work. |
100 | | |
| 100 | |
101 | 101 | * :file:`urls.py`: The URL declarations for this Django project; a "table of |
102 | 102 | contents" of your Django-powered site. You can read more about URLs in |
103 | 103 | :ref:`topics-http-urls`. |
… |
… |
|
137 | 137 | on port 8000. If you want to change the server's port, pass it as a |
138 | 138 | command-line argument. For instance, this command starts the server on port |
139 | 139 | 8080: |
140 | | |
| 140 | |
141 | 141 | .. code-block:: bash |
142 | 142 | |
143 | 143 | python manage.py runserver 8080 |
… |
… |
|
155 | 155 | |
156 | 156 | * :setting:`DATABASE_ENGINE` -- Either 'postgresql_psycopg2', 'mysql' or |
157 | 157 | 'sqlite3'. Other backends are :setting:`also available <DATABASE_ENGINE>`. |
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 |
162 | | that file. If the file doesn't exist, it will automatically be created |
163 | | when you synchronize the database for the first time (see below). |
164 | | |
165 | | When specifying the path, always use forward slashes, even on Windows |
| 161 | :setting:`DATABASE_NAME` should be the full absolute path, including |
| 162 | filename, of that file. If the file doesn't exist, it will automatically |
| 163 | be created when you synchronize the database for the first time (see |
| 164 | below). |
| 165 | |
| 166 | When specifying the path, always use forward slashes, even on Windows |
166 | 167 | (e.g. ``C:/homes/user/mysite/sqlite3.db``). |
167 | | |
| 168 | |
168 | 169 | * :setting:`DATABASE_USER` -- Your database username (not used for SQLite). |
169 | | |
| 170 | |
170 | 171 | * :setting:`DATABASE_PASSWORD` -- Your database password (not used for |
171 | 172 | SQLite). |
172 | | |
| 173 | |
173 | 174 | * :setting:`DATABASE_HOST` -- The host your database is on. Leave this as an |
174 | 175 | empty string if your database server is on the same physical machine (not |
175 | 176 | used for SQLite). |
… |
… |
|
585 | 586 | prompt, but also because objects' representations are used throughout Django's |
586 | 587 | automatically-generated admin. |
587 | 588 | |
588 | | .. admonition:: Why :meth:`~django.db.models.Model.__unicode__` and not |
| 589 | .. admonition:: Why :meth:`~django.db.models.Model.__unicode__` and not |
589 | 590 | :meth:`django.db.models.Model.__str__`? |
590 | 591 | |
591 | 592 | If you're familiar with Python, you might be in the habit of adding |
-
diff --git a/docs/misc/api-stability.txt b/docs/misc/api-stability.txt
a
|
b
|
|
17 | 17 | - All the public APIs -- everything documented in the linked documents below, |
18 | 18 | and all methods that don't begin with an underscore -- will not be moved or |
19 | 19 | renamed without providing backwards-compatible aliases. |
20 | | |
| 20 | |
21 | 21 | - If new features are added to these APIs -- which is quite possible -- |
22 | 22 | they will not break or change the meaning of existing methods. In other |
23 | 23 | words, "stable" does not (necessarily) mean "complete." |
24 | | |
| 24 | |
25 | 25 | - If, for some reason, an API declared stable must be removed or replaced, it |
26 | 26 | will be declared deprecated but will remain in the API for at least two |
27 | 27 | minor version releases. Warnings will be issued when the deprecated method |
28 | 28 | is called. |
29 | | |
| 29 | |
30 | 30 | See :ref:`official-releases` for more details on how Django's version |
31 | 31 | numbering scheme works, and how features will be deprecated. |
32 | | |
| 32 | |
33 | 33 | - We'll only break backwards compatibility of these APIs if a bug or |
34 | 34 | security hole makes it completely unavoidable. |
35 | 35 | |
… |
… |
|
43 | 43 | - :ref:`Authorization <topics-auth>` |
44 | 44 | |
45 | 45 | - :ref:`Caching <topics-cache>`. |
46 | | |
| 46 | |
47 | 47 | - :ref:`Model definition, managers, querying and transactions |
48 | 48 | <topics-db-index>` |
49 | | |
| 49 | |
50 | 50 | - :ref:`Sending e-mail <topics-email>`. |
51 | | |
| 51 | |
52 | 52 | - :ref:`File handling and storage <topics-files>` |
53 | | |
| 53 | |
54 | 54 | - :ref:`Forms <topics-forms-index>` |
55 | | |
| 55 | |
56 | 56 | - :ref:`HTTP request/response handling <topics-http-index>`, including file |
57 | 57 | uploads, middleware, sessions, URL resolution, view, and shortcut APIs. |
58 | | |
| 58 | |
59 | 59 | - :ref:`Generic views <topics-http-generic-views>`. |
60 | 60 | |
61 | 61 | - :ref:`Internationalization <topics-i18n>`. |
62 | | |
| 62 | |
63 | 63 | - :ref:`Pagination <topics-pagination>` |
64 | | |
| 64 | |
65 | 65 | - :ref:`Serialization <topics-serialization>` |
66 | | |
| 66 | |
67 | 67 | - :ref:`Signals <topics-signals>` |
68 | | |
| 68 | |
69 | 69 | - :ref:`Templates <topics-templates>`, including the language, Python-level |
70 | 70 | :ref:`template APIs <ref-templates-index>`, and :ref:`custom template tags |
71 | 71 | and libraries <howto-custom-template-tags>`. We may add new template |
72 | 72 | tags in the future and the names may inadvertently clash with |
73 | 73 | external template tags. Before adding any such tags, we'll ensure that |
74 | 74 | Django raises an error if it tries to load tags with duplicate names. |
75 | | |
| 75 | |
76 | 76 | - :ref:`Testing <topics-testing>` |
77 | 77 | |
78 | 78 | - :ref:`django-admin utility <ref-django-admin>`. |
79 | | |
| 79 | |
80 | 80 | - :ref:`Built-in middleware <ref-middleware>` |
81 | | |
| 81 | |
82 | 82 | - :ref:`Request/response objects <ref-request-response>`. |
83 | | |
| 83 | |
84 | 84 | - :ref:`Settings <ref-settings>`. Note, though that while the :ref:`list of |
85 | 85 | built-in settings <ref-settings>` can be considered complete we may -- and |
86 | 86 | probably will -- add new settings in future versions. This is one of those |
87 | 87 | places where "'stable' does not mean 'complete.'" |
88 | | |
| 88 | |
89 | 89 | - :ref:`Built-in signals <ref-signals>`. Like settings, we'll probably add |
90 | 90 | new signals in the future, but the existing ones won't break. |
91 | | |
| 91 | |
92 | 92 | - :ref:`Unicode handling <ref-unicode>`. |
93 | | |
| 93 | |
94 | 94 | - Everything covered by the :ref:`HOWTO guides <howto-index>`. |
95 | | |
| 95 | |
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 |
| 100 | the following parts of :mod:`django.utils` can be considered stable: |
100 | 101 | |
101 | | - ``django.utils.cache`` |
102 | | - ``django.utils.datastructures.SortedDict`` -- only this single class; the |
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`` |
110 | | |
| 102 | - :mod:`django.utils.cache` |
| 103 | - :class:`django.utils.datastructures.SortedDict` -- only this single |
| 104 | class; the rest of the module is for internal use. |
| 105 | - :mod:`django.utils.encoding` |
| 106 | - :mod:`django.utils.feedgenerator` |
| 107 | - :mod:`django.utils.http` |
| 108 | - :mod:`django.utils.safestring` |
| 109 | - :mod:`django.utils.translation` |
| 110 | - :mod:`django.utils.tzinfo` |
| 111 | |
111 | 112 | Exceptions |
112 | 113 | ========== |
113 | 114 | |
… |
… |
|
119 | 120 | |
120 | 121 | If we become aware of a security problem -- hopefully by someone following our |
121 | 122 | :ref:`security reporting policy <reporting-security-issues>` -- we'll do |
122 | | everything necessary to fix it. This might mean breaking backwards compatibility; security trumps the compatibility guarantee. |
| 123 | everything necessary to fix it. This might mean breaking backwards |
| 124 | compatibility; security trumps the compatibility guarantee. |
123 | 125 | |
124 | 126 | Contributed applications (``django.contrib``) |
125 | 127 | --------------------------------------------- |
… |
… |
|
129 | 131 | releases. As the web evolves, Django must evolve with it. |
130 | 132 | |
131 | 133 | However, any changes to contrib apps will come with an important guarantee: |
132 | | we'll make sure it's always possible to use an older version of a contrib app if |
133 | | we need to make changes. Thus, if Django 1.5 ships with a backwards-incompatible |
134 | | ``django.contrib.flatpages``, we'll make sure you can still use the Django 1.4 |
135 | | version alongside Django 1.5. This will continue to allow for easy upgrades. |
| 134 | we'll make sure it's always possible to use an older version of a contrib app |
| 135 | if we need to make changes. Thus, if Django 1.5 ships with a |
| 136 | backwards-incompatible ``django.contrib.flatpages``, we'll make sure you can |
| 137 | still use the Django 1.4 version alongside Django 1.5. This will continue to |
| 138 | allow for easy upgrades. |
136 | 139 | |
137 | | Historically, apps in ``django.contrib`` have been more stable than the core, so |
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``. |
| 140 | Historically, apps in :mod:`django.contrib` have been more stable than the |
| 141 | core, so in practice we probably won't have to ever make this exception. |
| 142 | However, it's worth noting if you're building apps that depend on |
| 143 | :mod:`django.contrib`. |
140 | 144 | |
141 | 145 | APIs marked as internal |
142 | 146 | ----------------------- |
… |
… |
|
146 | 150 | - Some documentation refers to internals and mentions them as such. If the |
147 | 151 | documentation says that something is internal, we reserve the right to |
148 | 152 | change it. |
149 | | |
| 153 | |
150 | 154 | - Functions, methods, and other objects prefixed by a leading underscore |
151 | 155 | (``_``). This is the standard Python way of indicating that something is |
152 | 156 | private; if any method starts with a single ``_``, it's an internal API. |
-
diff --git a/docs/misc/design-philosophies.txt b/docs/misc/design-philosophies.txt
a
|
b
|
|
69 | 69 | The `discussion of DRY on the Portland Pattern Repository`__ |
70 | 70 | |
71 | 71 | __ http://c2.com/cgi/wiki?DontRepeatYourself |
72 | | |
| 72 | |
73 | 73 | .. _explicit-is-better-than-implicit: |
74 | 74 | |
75 | 75 | Explicit is better than implicit |
… |
… |
|
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 |
134 | | optional performance booster for the common case of selecting "every related |
| 133 | This is also why the ``select_related()`` :class:`QuerySet` method exists. It's |
| 134 | an optional performance booster for the common case of selecting "every related |
135 | 135 | object." |
136 | 136 | |
137 | 137 | Terse, powerful syntax |
-
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` |
| 116 | model:: |
116 | 117 | |
117 | 118 | class FlatPageAdmin(admin.ModelAdmin): |
118 | 119 | fieldsets = ( |
… |
… |
|
184 | 185 | Use this option as an alternative to ``fieldsets`` if the layout does not |
185 | 186 | matter and if you want to only show a subset of the available fields in the |
186 | 187 | form. For example, you could define a simpler version of the admin form for |
187 | | the ``django.contrib.flatpages.FlatPage`` model as follows:: |
| 188 | the :class:`django.contrib.flatpages.FlatPage` model as follows:: |
188 | 189 | |
189 | 190 | class FlatPageAdmin(admin.ModelAdmin): |
190 | 191 | fields = ('url', 'title', 'content') |
… |
… |
|
411 | 412 | field should be either a ``BooleanField``, ``CharField``, ``DateField``, |
412 | 413 | ``DateTimeField``, ``IntegerField`` or ``ForeignKey``. |
413 | 414 | |
414 | | This example, taken from the ``django.contrib.auth.models.User`` model, shows |
415 | | how both ``list_display`` and ``list_filter`` work:: |
| 415 | This example, taken from the :class:`django.contrib.auth.models.User` model, |
| 416 | shows how both ``list_display`` and ``list_filter`` work:: |
416 | 417 | |
417 | 418 | class UserAdmin(admin.ModelAdmin): |
418 | 419 | list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff') |
… |
… |
|
495 | 496 | radio_fields = {"group": admin.VERTICAL} |
496 | 497 | |
497 | 498 | You have the choice of using ``HORIZONTAL`` or ``VERTICAL`` from the |
498 | | ``django.contrib.admin`` module. |
| 499 | :mod:`django.contrib.admin` module. |
499 | 500 | |
500 | 501 | Don't include a field in ``radio_fields`` unless it's a ``ForeignKey`` or has |
501 | 502 | ``choices`` set. |
… |
… |
|
646 | 647 | } |
647 | 648 | js = ("my_code.js",) |
648 | 649 | |
649 | | Keep in mind that this will be prepended with ``MEDIA_URL``. The same rules |
650 | | apply as :ref:`regular media definitions on forms <topics-forms-media>`. |
| 650 | Keep in mind that this will be prepended with :setting:`MEDIA_URL`. The same |
| 651 | rules apply as :ref:`regular media definitions on forms <topics-forms-media>`. |
651 | 652 | |
652 | 653 | Adding custom validation to the admin |
653 | 654 | ------------------------------------- |
… |
… |
|
871 | 872 | |
872 | 873 | If you want to allow editing and creating ``Image`` instance on the ``Product`` |
873 | 874 | add/change views you can simply use ``GenericInlineModelAdmin`` provided by |
874 | | ``django.contrib.contenttypes.generic``. In your ``admin.py`` for this |
| 875 | :mod:`django.contrib.contenttypes.generic`. In your ``admin.py`` for this |
875 | 876 | example app:: |
876 | 877 | |
877 | 878 | from django.contrib import admin |
… |
… |
|
889 | 890 | |
890 | 891 | admin.site.register(Product, ProductAdmin) |
891 | 892 | |
892 | | ``django.contrib.contenttypes.generic`` provides both a ``GenericTabularInline`` |
893 | | and ``GenericStackedInline`` and behave just like any other inline. See the |
| 893 | :mod:`django.contrib.contenttypes.generic` provides both a |
| 894 | ``GenericTabularInline`` and ``GenericStackedInline`` and behave just like any |
| 895 | other inline. See the |
894 | 896 | :ref:`contenttypes documentation <ref-contrib-contenttypes>` for more specific |
895 | 897 | information. |
896 | 898 | |
… |
… |
|
898 | 900 | ========================== |
899 | 901 | |
900 | 902 | It is relatively easy to override many of the templates which the admin module |
901 | | uses to generate the various pages of an admin site. You can even override a few |
902 | | of these templates for a specific app, or a specific model. |
| 903 | uses to generate the various pages of an admin site. You can even override a |
| 904 | few of these templates for a specific app, or a specific model. |
903 | 905 | |
904 | 906 | Set up your projects admin template directories |
905 | 907 | ----------------------------------------------- |
… |
… |
|
907 | 909 | The admin template files are located in the ``contrib/admin/templates/admin`` |
908 | 910 | directory. |
909 | 911 | |
910 | | In order to override one or more of them, first create an ``admin`` directory in |
911 | | your project's ``templates`` directory. This can be any of the directories you |
912 | | specified in ``TEMPLATE_DIRS``. |
| 912 | In order to override one or more of them, first create an ``admin`` directory |
| 913 | in your project's ``templates`` directory. This can be any of the directories |
| 914 | you specified in :setting:`TEMPLATE_DIRS`. |
913 | 915 | |
914 | 916 | Within this ``admin`` directory, create sub-directories named after your app. |
915 | 917 | Within these app subdirectories create sub-directories named after your models. |
916 | 918 | Note, that the admin app will lowercase the model name when looking for the |
917 | | directory, so make sure you name the directory in all lowercase if you are going |
918 | | to run your app on a case-sensitive filesystem. |
| 919 | directory, so make sure you name the directory in all lowercase if you are |
| 920 | going to run your app on a case-sensitive filesystem. |
919 | 921 | |
920 | 922 | To override an admin template for a specific app, copy and edit the template |
921 | 923 | from the ``django/contrib/admin/templates/admin`` directory, and save it to one |
… |
… |
|
938 | 940 | necessary nor advisable to replace an entire template. It is almost always |
939 | 941 | better to override only the section of the template which you need to change. |
940 | 942 | |
941 | | To continue the example above, we want to add a new link next to the ``History`` |
942 | | tool for the ``Page`` model. After looking at ``change_form.html`` we determine |
943 | | that we only need to override the ``object-tools`` block. Therefore here is our |
944 | | new ``change_form.html`` : |
| 943 | To continue the example above, we want to add a new link next to the |
| 944 | ``History`` tool for the ``Page`` model. After looking at ``change_form.html`` |
| 945 | we determine that we only need to override the ``object-tools`` block. |
| 946 | Therefore here is our new ``change_form.html``: |
945 | 947 | |
946 | 948 | .. code-block:: html+django |
947 | 949 | |
… |
… |
|
984 | 986 | |
985 | 987 | Some of the admin templates, such as ``change_list_request.html`` are used |
986 | 988 | to render custom inclusion tags. These may be overridden, but in such cases |
987 | | you are probably better off creating your own version of the tag in question |
988 | | and giving it a different name. That way you can use it selectively. |
| 989 | you are probably better off creating your own version of the tag in |
| 990 | question and giving it a different name. That way you can use it |
| 991 | selectively. |
989 | 992 | |
990 | 993 | Root and login templates |
991 | 994 | ------------------------ |
992 | 995 | |
993 | 996 | If you wish to change the index or login templates, you are better off creating |
994 | | your own ``AdminSite`` instance (see below), and changing the ``index_template`` |
995 | | or ``login_template`` properties. |
| 997 | your own ``AdminSite`` instance (see below), and changing the |
| 998 | ``index_template`` or ``login_template`` properties. |
996 | 999 | |
997 | 1000 | ``AdminSite`` objects |
998 | 1001 | ===================== |
999 | 1002 | |
1000 | 1003 | A Django administrative site is represented by an instance of |
1001 | | ``django.contrib.admin.sites.AdminSite``; by default, an instance of |
| 1004 | :class:`django.contrib.admin.sites.AdminSite`; by default, an instance of |
1002 | 1005 | this class is created as ``django.contrib.admin.site`` and you can |
1003 | 1006 | register your models and ``ModelAdmin`` instances with it. |
1004 | 1007 | |
… |
… |
|
1031 | 1034 | ) |
1032 | 1035 | |
1033 | 1036 | Above we used ``admin.autodiscover()`` to automatically load the |
1034 | | ``INSTALLED_APPS`` admin.py modules. |
| 1037 | :setting:`INSTALLED_APPS` admin.py modules. |
1035 | 1038 | |
1036 | 1039 | In this example, we register the ``AdminSite`` instance |
1037 | 1040 | ``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." |
33 | | You can change this to provide custom comment models and forms, though this is |
34 | | currently undocumented. |
| 32 | The app (i.e. entry in :setting:`INSTALLED_APPS`) responsible for all "business |
| 33 | logic." You can change this to provide custom comment models and forms, though |
| 34 | this is 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 |
20 | | ``manage.py syncdb``. |
| 19 | ``'django.contrib.admin'``) to your :setting:`INSTALLED_APPS` setting and |
| 20 | re-run ``manage.py syncdb``. |
21 | 21 | |
22 | 22 | .. _"batteries included" philosophy: http://docs.python.org/tut/node12.html#batteries-included |
23 | 23 | |
… |
… |
|
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, |
68 | | containing useful code that is not specific to one particular country or |
69 | | culture. Currently, it defines date and datetime input fields based on those |
70 | | from :ref:`forms <topics-forms-index>`, but with non-US default formats. |
71 | | Here's an example of how to use them:: |
| 67 | The :mod:`django.contrib.localflavor` package also includes a ``generic`` |
| 68 | subpackage, containing useful code that is not specific to one particular |
| 69 | country or culture. Currently, it defines date and datetime input fields based |
| 70 | on those from :ref:`forms <topics-forms-index>`, but with non-US default |
| 71 | formats. Here's an example of how to use them:: |
72 | 72 | |
73 | 73 | from django import forms |
74 | 74 | from django.contrib.localflavor import generic |
… |
… |
|
118 | 118 | |
119 | 119 | .. class:: ar.forms.ARPostalCodeField |
120 | 120 | |
121 | | A form field that validates input as either a classic four-digit Argentinian |
122 | | postal code or a CPA_. |
| 121 | A form field that validates input as either a classic four-digit |
| 122 | Argentinian postal code or a CPA_. |
123 | 123 | |
124 | 124 | .. _CPA: http://www.correoargentino.com.ar/consulta_cpa/home.php |
125 | 125 | |
126 | 126 | .. class:: ar.forms.ARDNIField |
127 | 127 | |
128 | | A form field that validates input as a Documento Nacional de Identidad (DNI) |
129 | | number. |
| 128 | A form field that validates input as a Documento Nacional de Identidad |
| 129 | (DNI) number. |
130 | 130 | |
131 | 131 | .. class:: ar.forms.ARCUITField |
132 | 132 | |
… |
… |
|
147 | 147 | |
148 | 148 | .. class:: au.forms.AUPhoneNumberField |
149 | 149 | |
150 | | A form field that validates input as an Australian phone number. Valid numbers |
151 | | have ten digits. |
| 150 | A form field that validates input as an Australian phone number. Valid |
| 151 | numbers have ten digits. |
152 | 152 | |
153 | 153 | .. class:: au.forms.AUStateSelect |
154 | 154 | |
155 | | A ``Select`` widget that uses a list of Australian states/territories as its |
156 | | choices. |
| 155 | A ``Select`` widget that uses a list of Australian states/territories as |
| 156 | its choices. |
157 | 157 | |
158 | 158 | Austria (``at``) |
159 | 159 | ================ |
… |
… |
|
164 | 164 | |
165 | 165 | .. class:: at.forms.ATStateSelect |
166 | 166 | |
167 | | A ``Select`` widget that uses a list of Austrian states as its choices. |
| 167 | A ``Select`` widget that uses a list of Austrian states as its choices. |
168 | 168 | |
169 | 169 | .. class:: at.forms.ATSocialSecurityNumberField |
170 | 170 | |
171 | | A form field that validates its input as an Austrian social security number. |
| 171 | A form field that validates its input as an Austrian social security |
| 172 | number. |
172 | 173 | |
173 | 174 | Brazil (``br``) |
174 | 175 | =============== |
175 | 176 | |
176 | 177 | .. class:: br.forms.BRPhoneNumberField |
177 | 178 | |
178 | | A form field that validates input as a Brazilian phone number, with the format |
179 | | XX-XXXX-XXXX. |
| 179 | A form field that validates input as a Brazilian phone number, with the |
| 180 | format XX-XXXX-XXXX. |
180 | 181 | |
181 | 182 | .. class:: br.forms.BRZipCodeField |
182 | 183 | |
… |
… |
|
193 | 194 | |
194 | 195 | .. class:: ca.forms.CAPhoneNumberField |
195 | 196 | |
196 | | A form field that validates input as a Canadian phone number, with the format |
197 | | XXX-XXX-XXXX. |
| 197 | A form field that validates input as a Canadian phone number, with the |
| 198 | format XXX-XXX-XXXX. |
198 | 199 | |
199 | 200 | .. class:: ca.forms.CAPostalCodeField |
200 | 201 | |
201 | | A form field that validates input as a Canadian postal code, with the format |
202 | | XXX XXX. |
| 202 | A form field that validates input as a Canadian postal code, with the |
| 203 | format XXX XXX. |
203 | 204 | |
204 | 205 | .. class:: ca.forms.CAProvinceField |
205 | 206 | |
206 | | A form field that validates input as a Canadian province name or abbreviation. |
| 207 | A form field that validates input as a Canadian province name or |
| 208 | abbreviation. |
207 | 209 | |
208 | 210 | .. class:: ca.forms.CASocialInsuranceNumberField |
209 | 211 | |
210 | | A form field that validates input as a Canadian Social Insurance Number (SIN). |
211 | | A valid number must have the format XXX-XXX-XXX and pass a `Luhn mod-10 |
212 | | checksum`_. |
| 212 | A form field that validates input as a Canadian Social Insurance Number |
| 213 | (SIN). A valid number must have the format XXX-XXX-XXX and pass a |
| 214 | `Luhn mod-10 checksum`_. |
213 | 215 | |
214 | 216 | .. _Luhn mod-10 checksum: http://en.wikipedia.org/wiki/Luhn_algorithm |
215 | 217 | |
216 | 218 | .. class:: ca.forms.CAProvinceSelect |
217 | 219 | |
218 | | A ``Select`` widget that uses a list of Canadian provinces and territories as |
219 | | its choices. |
| 220 | A ``Select`` widget that uses a list of Canadian provinces and territories |
| 221 | as its choices. |
220 | 222 | |
221 | 223 | Chile (``cl``) |
222 | 224 | ============== |
223 | 225 | |
224 | 226 | .. class:: cl.forms.CLRutField |
225 | 227 | |
226 | | A form field that validates input as a Chilean national identification number |
227 | | ('Rol Unico Tributario' or RUT). The valid format is XX.XXX.XXX-X. |
| 228 | A form field that validates input as a Chilean national identification |
| 229 | number ('Rol Unico Tributario' or RUT). The valid format is XX.XXX.XXX-X. |
228 | 230 | |
229 | 231 | .. class:: cl.forms.CLRegionSelect |
230 | 232 | |
… |
… |
|
381 | 383 | |
382 | 384 | .. class:: jp.forms.JPPrefectureSelect |
383 | 385 | |
384 | | A ``Select`` widget that uses a list of Japanese prefectures as its choices. |
| 386 | A ``Select`` widget that uses a list of Japanese prefectures as its |
| 387 | choices. |
385 | 388 | |
386 | 389 | Mexico (``mx``) |
387 | 390 | =============== |
… |
… |
|
407 | 410 | |
408 | 411 | .. class:: no.forms.NOMunicipalitySelect |
409 | 412 | |
410 | | A ``Select`` widget that uses a list of Norwegian municipalities (fylker) as |
411 | | its choices. |
| 413 | A ``Select`` widget that uses a list of Norwegian municipalities (fylker) |
| 414 | as its choices. |
412 | 415 | |
413 | 416 | Peru (``pe``) |
414 | 417 | ============= |
… |
… |
|
425 | 428 | |
426 | 429 | .. class:: pt.forms.PEDepartmentSelect |
427 | 430 | |
428 | | A ``Select`` widget that uses a list of Peruvian Departments as its choices. |
| 431 | A ``Select`` widget that uses a list of Peruvian Departments as its |
| 432 | choices. |
429 | 433 | |
430 | 434 | Poland (``pl``) |
431 | 435 | =============== |
432 | 436 | |
433 | 437 | .. class:: pl.forms.PLNationalIdentificationNumberField |
434 | 438 | |
435 | | A form field that validates input as a Polish national identification number |
436 | | (PESEL_). |
| 439 | A form field that validates input as a Polish national identification |
| 440 | number (PESEL_). |
437 | 441 | |
438 | 442 | .. _PESEL: http://en.wikipedia.org/wiki/PESEL |
439 | 443 | |
… |
… |
|
483 | 487 | |
484 | 488 | A form field that validates its input as a Romanian county (judet) name or |
485 | 489 | abbreviation. It normalizes the input to the standard vehicle registration |
486 | | abbreviation for the given county. This field will only accept names written |
487 | | with diacritics; consider using ROCountySelect as an alternative. |
| 490 | abbreviation for the given county. This field will only accept names |
| 491 | written with diacritics; consider using ROCountySelect as an alternative. |
488 | 492 | |
489 | 493 | .. class:: ro.forms.ROCountySelect |
490 | 494 | |
… |
… |
|
493 | 497 | |
494 | 498 | .. class:: ro.forms.ROIBANField |
495 | 499 | |
496 | | A form field that validates its input as a Romanian International Bank |
| 500 | A form field that validates its input as a Romanian International Bank |
497 | 501 | Account Number (IBAN). The valid format is ROXX-XXXX-XXXX-XXXX-XXXX-XXXX, |
498 | 502 | with or without hyphens. |
499 | 503 | |
… |
… |
|
652 | 656 | |
653 | 657 | .. class:: us.models.PhoneNumberField |
654 | 658 | |
655 | | A :class:`CharField` that checks that the value is a valid U.S.A.-style phone |
656 | | number (in the format ``XXX-XXX-XXXX``). |
| 659 | A :class:`CharField` that checks that the value is a valid U.S.A.-style |
| 660 | phone number (in the format ``XXX-XXX-XXXX``). |
657 | 661 | |
658 | 662 | .. class:: us.models.USStateField |
659 | 663 | |
-
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
|
|
124 | 124 | non-unique) with the default collation. |
125 | 125 | |
126 | 126 | In many cases, this default will not be a problem. However, if you really want |
127 | | case-sensitive comparisons on a particular column or table, you would change |
128 | | the column or table to use the ``utf8_bin`` collation. The main thing to be |
129 | | aware of in this case is that if you are using MySQLdb 1.2.2, the database backend in Django will then return |
130 | | bytestrings (instead of unicode strings) for any character fields it returns |
131 | | receive from the database. This is a strong variation from Django's normal |
132 | | practice of *always* returning unicode strings. It is up to you, the |
133 | | developer, to handle the fact that you will receive bytestrings if you |
134 | | configure your table(s) to use ``utf8_bin`` collation. Django itself should work |
135 | | smoothly with such columns, but if your code must be prepared to call |
136 | | ``django.utils.encoding.smart_unicode()`` at times if it really wants to work |
137 | | with consistent data -- Django will not do this for you (the database backend |
138 | | layer and the model population layer are separated internally so the database |
139 | | layer doesn't know it needs to make this conversion in this one particular |
140 | | case). |
| 127 | case-sensitive comparisons on a particular column or table, you would change the |
| 128 | column or table to use the ``utf8_bin`` collation. The main thing to be aware of |
| 129 | in this case is that if you are using MySQLdb 1.2.2, the database backend in |
| 130 | Django will then return bytestrings (instead of unicode strings) for any |
| 131 | character fields it returns receive from the database. This is a strong |
| 132 | variation from Django's normal practice of *always* returning unicode strings. |
| 133 | It is up to you, the developer, to handle the fact that you will receive |
| 134 | bytestrings if you configure your table(s) to use ``utf8_bin`` collation. Django |
| 135 | itself should work smoothly with such columns, but if your code must be prepared |
| 136 | to call ``django.utils.encoding.smart_unicode()`` at times if it really wants to |
| 137 | work with consistent data -- Django will not do this for you (the database |
| 138 | backend layer and the model population layer are separated internally so the |
| 139 | database layer doesn't know it needs to make this conversion in this one |
| 140 | particular case). |
141 | 141 | |
142 | 142 | If you're using MySQLdb 1.2.1p2, Django's standard |
143 | 143 | :class:`~django.db.models.CharField` class will return unicode strings even |
… |
… |
|
163 | 163 | Connecting to the database |
164 | 164 | -------------------------- |
165 | 165 | |
166 | | Refer to the :ref:`settings documentation <ref-settings>`. |
| 166 | Refer to the :ref:`settings documentation <ref-settings>`. |
167 | 167 | |
168 | 168 | Connection settings are used in this order: |
169 | 169 | |
… |
… |
|
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 |
178 | | anything in a `MySQL option file`_. |
| 176 | In other words, if you set the name of the database in |
| 177 | :setting:`DATABASE_OPTIONS`, this will take precedence over |
| 178 | :setting:`DATABASE_NAME`, which would override anything in a `MySQL option |
| 179 | file`_. |
179 | 180 | |
180 | 181 | Here's a sample configuration which uses a MySQL option file:: |
181 | 182 | |
… |
… |
|
262 | 263 | |
263 | 264 | .. _sqlite-notes: |
264 | 265 | |
265 | | SQLite notes |
266 | | ============ |
267 | | |
| 266 | SQLite notes |
| 267 | ============ |
| 268 | |
268 | 269 | SQLite_ provides an excellent development alternative for applications that |
269 | 270 | are predominantly read-only or require a smaller installation footprint. As |
270 | 271 | with all database servers, though, there are some differences that are |
… |
… |
|
294 | 295 | ``OperationalError: ORDER BY terms must not be non-integer constants``. The |
295 | 296 | problem can be solved updating SQLite to version 3.3.6 or newer, possibly also |
296 | 297 | updating the ``pysqlite2`` Python module in the process. |
297 | | |
298 | | .. _contain a bug: http://www.sqlite.org/cvstrac/tktview?tn=1768 |
299 | | |
300 | | This has a very low impact because 3.3.6 was released in April 2006, so most |
301 | | current binary distributions for different platforms include newer version of |
302 | | SQLite usable from Python through either the ``pysqlite2`` or the ``sqlite3`` |
303 | | modules. |
304 | | |
305 | | However, in the case of Windows, the official binary distribution of the stable |
306 | | release of Python 2.5 (2.5.2, as of this writing) includes SQLite 3.3.4, so the bug can |
307 | | make itself evident in that platform. There are (as of Django 1.0) even three |
308 | | tests in the Django test suite that will fail when run under this setup. As |
309 | | described above, this can be solved by downloading and installing a newer |
310 | | version of ``pysqlite2`` (``pysqlite-2.x.x.win32-py2.5.exe``) that includes and |
311 | | uses a newer version of SQLite. Python 2.6 ships with a newer version of |
312 | | SQLite and is not affected by this issue. |
| 298 | |
| 299 | .. _contain a bug: http://www.sqlite.org/cvstrac/tktview?tn=1768 |
| 300 | |
| 301 | This has a very low impact because 3.3.6 was released in April 2006, so most |
| 302 | current binary distributions for different platforms include newer version of |
| 303 | SQLite usable from Python through either the ``pysqlite2`` or the ``sqlite3`` |
| 304 | modules. |
| 305 | |
| 306 | However, in the case of Windows, the official binary distribution of the stable |
| 307 | release of Python 2.5 (2.5.2, as of this writing) includes SQLite 3.3.4, so the |
| 308 | bug can make itself evident in that platform. There are (as of Django 1.0) even |
| 309 | three tests in the Django test suite that will fail when run under this setup. |
| 310 | As described above, this can be solved by downloading and installing a newer |
| 311 | version of ``pysqlite2`` (``pysqlite-2.x.x.win32-py2.5.exe``) that includes and |
| 312 | uses a newer version of SQLite. Python 2.6 ships with a newer version of SQLite |
| 313 | and is not affected by this issue. |
313 | 314 | |
314 | 315 | If you are in such platform and find yourself in the need to update |
315 | 316 | ``pysqlite``/SQLite, you will also need to manually modify the |
… |
… |
|
348 | 349 | * CREATE SEQUENCE |
349 | 350 | * CREATE PROCEDURE |
350 | 351 | * CREATE TRIGGER |
351 | | |
| 352 | |
352 | 353 | To run Django's test suite, the user needs these *additional* privileges: |
353 | 354 | |
354 | 355 | * CREATE USER |
355 | 356 | * DROP USER |
356 | 357 | * CREATE TABLESPACE |
357 | 358 | * DROP TABLESPACE |
358 | | |
| 359 | |
359 | 360 | Connecting to the database |
360 | 361 | -------------------------- |
361 | 362 | |
… |
… |
|
379 | 380 | DATABASE_HOST = 'dbprod01ned.mycompany.com' |
380 | 381 | DATABASE_PORT = '1540' |
381 | 382 | |
382 | | You should supply both :setting:`DATABASE_HOST` and :setting:`DATABASE_PORT`, or leave both |
383 | | as empty strings. |
| 383 | You should supply both :setting:`DATABASE_HOST` and :setting:`DATABASE_PORT`, or |
| 384 | leave both as empty strings. |
384 | 385 | |
385 | 386 | Tablespace options |
386 | 387 | ------------------ |
-
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`` |
63 | | contains the string ``'mysite.blog'``, the app name is ``blog``. |
| 62 | the package containing your models. For example, if your |
| 63 | :setting:`INSTALLED_APPS` contains the string ``'mysite.blog'``, the app name is |
| 64 | ``blog``. |
64 | 65 | |
65 | 66 | Determining the version |
66 | 67 | ----------------------- |
… |
… |
|
152 | 153 | it when running interactively. |
153 | 154 | |
154 | 155 | This command is only available if Django's :ref:`authentication system |
155 | | <topics-auth>` (``django.contrib.auth``) is installed. |
| 156 | <topics-auth>` (:mod:`django.contrib.auth`) is installed. |
156 | 157 | |
157 | 158 | dbshell |
158 | 159 | ------- |
… |
… |
|
160 | 161 | .. django-admin:: dbshell |
161 | 162 | |
162 | 163 | Runs the command-line client for the database engine specified in your |
163 | | ``DATABASE_ENGINE`` setting, with the connection parameters specified in your |
164 | | ``DATABASE_USER``, ``DATABASE_PASSWORD``, etc., settings. |
| 164 | :setting:`DATABASE_ENGINE` setting, with the connection parameters specified in |
| 165 | your :setting:`DATABASE_USER`, :setting:`DATABASE_PASSWORD`, etc., settings. |
165 | 166 | |
166 | 167 | * For PostgreSQL, this runs the ``psql`` command-line client. |
167 | 168 | * For MySQL, this runs the ``mysql`` command-line client. |
… |
… |
|
181 | 182 | settings. |
182 | 183 | |
183 | 184 | Settings that don't appear in the defaults are followed by ``"###"``. For |
184 | | example, the default settings don't define ``ROOT_URLCONF``, so |
| 185 | example, the default settings don't define :setting:`ROOT_URLCONF`, so |
185 | 186 | ``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``. |
186 | 187 | |
187 | 188 | Note that Django's default settings live in ``django/conf/global_settings.py``, |
… |
… |
|
252 | 253 | --------- |
253 | 254 | |
254 | 255 | Introspects the database tables in the database pointed-to by the |
255 | | ``DATABASE_NAME`` setting and outputs a Django model module (a ``models.py`` |
256 | | file) to standard output. |
| 256 | :setting:`DATABASE_NAME` setting and outputs a Django model module (a |
| 257 | ``models.py`` file) to standard output. |
257 | 258 | |
258 | 259 | Use this if you have a legacy database with which you'd like to use Django. |
259 | 260 | The script will inspect the database and create a model for each table within |
… |
… |
|
301 | 302 | Django will search in three locations for fixtures: |
302 | 303 | |
303 | 304 | 1. In the ``fixtures`` directory of every installed application |
304 | | 2. In any directory named in the ``FIXTURE_DIRS`` setting |
| 305 | 2. In any directory named in the :setting:`FIXTURE_DIRS` setting |
305 | 306 | 3. In the literal path named by the fixture |
306 | 307 | |
307 | 308 | Django will load any and all fixtures it finds in these locations that match |
… |
… |
|
336 | 337 | |
337 | 338 | would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed |
338 | 339 | application, ``<dirname>/foo/bar/mydata.json`` for each directory in |
339 | | ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``. |
| 340 | :setting:`FIXTURE_DIRS`, and the literal path ``foo/bar/mydata.json``. |
340 | 341 | |
341 | 342 | Note that the order in which fixture files are processed is undefined. However, |
342 | 343 | all fixture data is installed as a single transaction, so data in |
… |
… |
|
541 | 542 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
542 | 543 | |
543 | 544 | By default, the development server doesn't serve any static files for your site |
544 | | (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If |
| 545 | (such as CSS files, images, things under :setting:`MEDIA_URL` and so forth). If |
545 | 546 | you want to configure Django to serve static media, read :ref:`howto-static-files`. |
546 | 547 | |
547 | 548 | Turning off auto-reload |
… |
… |
|
645 | 646 | syncdb |
646 | 647 | ------ |
647 | 648 | |
648 | | Creates the database tables for all apps in ``INSTALLED_APPS`` whose tables |
649 | | have not already been created. |
| 649 | Creates the database tables for all apps in :setting:`INSTALLED_APPS` whose |
| 650 | tables have not already been created. |
650 | 651 | |
651 | 652 | Use this command when you've added new applications to your project and want to |
652 | 653 | install them in the database. This includes any apps shipped with Django that |
653 | | might be in ``INSTALLED_APPS`` by default. When you start a new project, run |
654 | | this command to install the default apps. |
| 654 | might be in :setting:`INSTALLED_APPS` by default. When you start a new project, |
| 655 | run this command to install the default apps. |
655 | 656 | |
656 | 657 | .. admonition:: Syncdb will not alter existing tables |
657 | 658 | |
… |
… |
|
666 | 667 | to match, use the ``sql`` command to display the new SQL structure and |
667 | 668 | compare that to your existing table schema to work out the changes. |
668 | 669 | |
669 | | If you're installing the ``django.contrib.auth`` application, ``syncdb`` will |
| 670 | If you're installing the :mod:`django.contrib.auth` application, ``syncdb`` will |
670 | 671 | give you the option of creating a superuser immediately. |
671 | 672 | |
672 | 673 | ``syncdb`` will also search for and install any fixture named ``initial_data`` |
… |
… |
|
763 | 764 | --addrport [port number or ipaddr:port] |
764 | 765 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
765 | 766 | |
766 | | Use ``--addrport`` to specify a different port, or IP address and port, from |
767 | | the default of 127.0.0.1:8000. This value follows exactly the same format and |
768 | | serves exactly the same function as the argument to the ``runserver`` subcommand. |
| 767 | Use ``--addrport`` to specify a different port, or IP address and port, from the |
| 768 | default of 127.0.0.1:8000. This value follows exactly the same format and serves |
| 769 | exactly the same function as the argument to the ``runserver`` subcommand. |
769 | 770 | |
770 | 771 | Examples: |
771 | 772 | |
… |
… |
|
799 | 800 | validate |
800 | 801 | -------- |
801 | 802 | |
802 | | Validates all installed models (according to the ``INSTALLED_APPS`` setting) |
803 | | and prints validation errors to standard output. |
| 803 | Validates all installed models (according to the :setting:`INSTALLED_APPS` |
| 804 | setting) and prints validation errors to standard output. |
804 | 805 | |
805 | 806 | Default options |
806 | 807 | =============== |
-
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, |
136 | | but also for "cleaning" it -- normalizing it to a consistent format. This is a |
137 | | nice feature, because it allows data for a particular field to be input in |
138 | | a variety of ways, always resulting in consistent output. |
| 135 | Each :class:`Field` in a :class:`Form` class is responsible not only for |
| 136 | validating data, but also for "cleaning" it -- normalizing it to a consistent |
| 137 | format. This is a nice feature, because it allows data for a particular field to |
| 138 | be input in 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`` |
148 | | object:: |
| 146 | Once you've created a :class:`Form` instance with a set of data and validated |
| 147 | it, you can access the clean data via the :attr:`cleaned_data` attribute of the |
| 148 | ``Form`` object:: |
149 | 149 | |
150 | 150 | >>> data = {'subject': 'hello', |
151 | 151 | ... 'message': 'Hi there', |
… |
… |
|
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`` -- |
164 | | always cleans the input into a Unicode string. We'll cover the encoding |
165 | | implications later in this document. |
| 163 | Note that any text-based field -- such as :class:`CharField` or |
| 164 | :class:`EmailField` -- always cleans the input into a Unicode string. We'll |
| 165 | cover the encoding 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 |
184 | | example, we pass a bunch of extra fields to the ``ContactForm`` constructor, |
185 | | but ``cleaned_data`` contains only the form's fields:: |
| 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 |
| 184 | this example, we pass a bunch of extra fields to the ``ContactForm`` |
| 185 | constructor, 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 |
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:: |
| 200 | :attr:`cleaned_data` will include a key and value for *all* fields defined in |
| 201 | the :class:`Form`, even if the data didn't include a value for fields that are |
| 202 | not required. In this example, the data dictionary doesn't include a value for |
| 203 | the ``nick_name`` field, but :attr:`cleaned_data` includes it, with an empty |
| 204 | value:: |
204 | 205 | |
205 | 206 | >>> class OptionalPersonForm(Form): |
206 | 207 | ... first_name = CharField() |
… |
… |
|
213 | 214 | >>> f.cleaned_data |
214 | 215 | {'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} |
215 | 216 | |
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 |
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 |
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. |
| 217 | In this above example, the :attr:`cleaned_data` value for ``nick_name`` is set |
| 218 | to an empty string, because ``nick_name`` is :class:`CharField`, and |
| 219 | :class:`CharField`\s treat empty values as an empty string. Each field type |
| 220 | knows what its "blank" value is -- e.g., for :class:`DateField`, it's ``None`` |
| 221 | instead of the empty string. For full details on each field's behavior in this |
| 222 | case, see the "Empty value" note for each field in the "Built-in :class:`Field` |
| 223 | classes" section below. |
222 | 224 | |
223 | 225 | You can write code to perform validation for particular form fields (based on |
224 | 226 | their name) or for the form as a whole (considering combinations of various |
… |
… |
|
227 | 229 | Outputting forms as HTML |
228 | 230 | ------------------------ |
229 | 231 | |
230 | | The second task of a ``Form`` object is to render itself as HTML. To do so, |
| 232 | The second task of a :class:`Form` object is to render itself as HTML. To do so, |
231 | 233 | simply ``print`` it:: |
232 | 234 | |
233 | 235 | >>> f = ContactForm() |
… |
… |
|
261 | 263 | ``</table>`` tags, nor does it include the ``<form>`` and ``</form>`` |
262 | 264 | tags or an ``<input type="submit">`` tag. It's your job to do that. |
263 | 265 | |
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 |
267 | | these are merely sensible defaults; you can specify which HTML to use for |
268 | | a given field by using widgets, which we'll explain shortly. |
| 266 | * Each field type has a default HTML representation. :class:`CharField` and |
| 267 | :class:`EmailField` are represented by an ``<input type="text">``. |
| 268 | :class:`BooleanField` is represented by an ``<input type="checkbox">``. |
| 269 | Note these are merely sensible defaults; you can specify which HTML to use |
| 270 | for a given field by using widgets, which we'll explain shortly. |
269 | 271 | |
270 | 272 | * The HTML ``name`` for each tag is taken directly from its attribute name |
271 | 273 | in the ``ContactForm`` class. |
… |
… |
|
288 | 290 | ``as_p()`` |
289 | 291 | ~~~~~~~~~~ |
290 | 292 | |
291 | | ``Form.as_p()`` renders the form as a series of ``<p>`` tags, with each ``<p>`` |
| 293 | :meth:`Form.as_p` renders the form as a series of ``<p>`` tags, with each ``<p>`` |
292 | 294 | containing one field:: |
293 | 295 | |
294 | 296 | >>> f = ContactForm() |
… |
… |
|
303 | 305 | ``as_ul()`` |
304 | 306 | ~~~~~~~~~~~ |
305 | 307 | |
306 | | ``Form.as_ul()`` renders the form as a series of ``<li>`` tags, with each |
| 308 | :meth:`Form.as_ul` renders the form as a series of ``<li>`` tags, with each |
307 | 309 | ``<li>`` containing one field. It does *not* include the ``<ul>`` or ``</ul>``, |
308 | 310 | so that you can specify any HTML attributes on the ``<ul>`` for flexibility:: |
309 | 311 | |
… |
… |
|
319 | 321 | ``as_table()`` |
320 | 322 | ~~~~~~~~~~~~~~ |
321 | 323 | |
322 | | Finally, ``Form.as_table()`` outputs the form as an HTML ``<table>``. This is |
| 324 | Finally, :meth:`Form.as_table` outputs the form as an HTML ``<table>``. This is |
323 | 325 | exactly the same as ``print``. In fact, when you ``print`` a form object, it |
324 | | calls its ``as_table()`` method behind the scenes:: |
| 326 | calls its :meth:`as_table` method behind the scenes:: |
325 | 327 | |
326 | 328 | >>> f = ContactForm() |
327 | 329 | >>> f.as_table() |
… |
… |
|
347 | 349 | This behavior is configurable, though, if you want to change the ``id`` |
348 | 350 | convention or remove HTML ``id`` attributes and ``<label>`` tags entirely. |
349 | 351 | |
350 | | Use the ``auto_id`` argument to the ``Form`` constructor to control the label |
351 | | and ``id`` behavior. This argument must be ``True``, ``False`` or a string. |
| 352 | Use the ``auto_id`` argument to the :class:`Form` constructor to control the |
| 353 | label and ``id`` behavior. This argument must be ``True``, ``False`` or a |
| 354 | string. |
352 | 355 | |
353 | 356 | If ``auto_id`` is ``False``, then the form output will not include ``<label>`` |
354 | 357 | tags nor ``id`` attributes:: |
… |
… |
|
442 | 445 | Notes on field ordering |
443 | 446 | ~~~~~~~~~~~~~~~~~~~~~~~ |
444 | 447 | |
445 | | In the ``as_p()``, ``as_ul()`` and ``as_table()`` shortcuts, the fields are |
446 | | displayed in the order in which you define them in your form class. For |
| 448 | In the :meth:`as_p`, :meth:`as_ul` and :meth:`as_table` shortcuts, the fields |
| 449 | are displayed in the order in which you define them in your form class. For |
447 | 450 | example, in the ``ContactForm`` example, the fields are defined in the order |
448 | | ``subject``, ``message``, ``sender``, ``cc_myself``. To reorder the HTML |
449 | | output, just change the order in which those fields are listed in the class. |
| 451 | ``subject``, ``message``, ``sender``, ``cc_myself``. To reorder the HTML output, |
| 452 | just change the order in which those fields are listed in the class. |
450 | 453 | |
451 | 454 | How errors are displayed |
452 | 455 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
453 | 456 | |
454 | | If you render a bound ``Form`` object, the act of rendering will automatically |
455 | | run the form's validation if it hasn't already happened, and the HTML output |
456 | | will include the validation errors as a ``<ul class="errorlist">`` near the |
457 | | field. The particular positioning of the error messages depends on the output |
458 | | method you're using:: |
| 457 | If you render a bound :class:`Form` object, the act of rendering will |
| 458 | automatically run the form's validation if it hasn't already happened, and the |
| 459 | HTML output will include the validation errors as a ``<ul class="errorlist">`` |
| 460 | near the field. The particular positioning of the error messages depends on the |
| 461 | output method you're using:: |
459 | 462 | |
460 | 463 | >>> data = {'subject': '', |
461 | 464 | ... 'message': 'Hi there', |
… |
… |
|
483 | 486 | Customizing the error list format |
484 | 487 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
485 | 488 | |
486 | | By default, forms use ``django.forms.util.ErrorList`` to format validation |
| 489 | By default, forms use :class:`django.forms.util.ErrorList` to format validation |
487 | 490 | errors. If you'd like to use an alternate class for displaying errors, you can |
488 | 491 | pass that in at construction time:: |
489 | 492 | |
… |
… |
|
506 | 509 | More granular output |
507 | 510 | ~~~~~~~~~~~~~~~~~~~~ |
508 | 511 | |
509 | | The ``as_p()``, ``as_ul()`` and ``as_table()`` methods are simply shortcuts for |
510 | | lazy developers -- they're not the only way a form object can be displayed. |
| 512 | The :meth:`as_p`, :meth:`as_ul` and :meth:`as_table` methods are simply |
| 513 | shortcuts for lazy developers -- they're not the only way a form object can be |
| 514 | displayed. |
511 | 515 | |
512 | 516 | To display the HTML for a single field in your form, use dictionary lookup |
513 | 517 | syntax using the field's name as the key, and print the resulting object:: |
… |
… |
|
549 | 553 | >>> print f['message'] |
550 | 554 | <input type="text" name="message" id="id_message" /> |
551 | 555 | |
552 | | For a field's list of errors, access the field's ``errors`` attribute. This |
| 556 | For a field's list of errors, access the field's :attr:`errors` attribute. This |
553 | 557 | is a list-like object that is displayed as an HTML ``<ul class="errorlist">`` |
554 | 558 | when printed:: |
555 | 559 | |
… |
… |
|
575 | 579 | |
576 | 580 | .. versionadded:: 1.0 |
577 | 581 | |
578 | | Dealing with forms that have ``FileField`` and ``ImageField`` fields |
| 582 | Dealing with forms that have :class:`FileField` and :class:`ImageField` fields |
579 | 583 | is a little more complicated than a normal form. |
580 | 584 | |
581 | 585 | Firstly, in order to upload files, you'll need to make sure that your |
… |
… |
|
586 | 590 | |
587 | 591 | Secondly, when you use the form, you need to bind the file data. File |
588 | 592 | data is handled separately to normal form data, so when your form |
589 | | contains a ``FileField`` and ``ImageField``, you will need to specify |
| 593 | contains a :class:`FileField` and :class:`ImageField`, you will need to specify |
590 | 594 | a second argument when you bind your form. So if we extend our |
591 | | ContactForm to include an ``ImageField`` called ``mugshot``, we |
| 595 | ContactForm to include an :class:`ImageField` called ``mugshot``, we |
592 | 596 | need to bind the file data containing the mugshot image:: |
593 | 597 | |
594 | 598 | # Bound form with an image field |
… |
… |
|
600 | 604 | >>> file_data = {'mugshot': SimpleUploadedFile('face.jpg', <file data>)} |
601 | 605 | >>> f = ContactFormWithMugshot(data, file_data) |
602 | 606 | |
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 |
| 607 | In practice, you will usually specify :attr:`request.FILES` as the source |
| 608 | of file data (just like you use :attr:`request.POST` as the source of |
605 | 609 | form data):: |
606 | 610 | |
607 | 611 | # Bound form with an image field, data from the request |
… |
… |
|
617 | 621 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
618 | 622 | |
619 | 623 | 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 |
| 624 | whether your form is a multipart form or not. The :meth:`is_multipart` method |
621 | 625 | tells you whether the form requires multipart encoding for submission:: |
622 | 626 | |
623 | 627 | >>> f = ContactFormWithMugshot() |
… |
… |
|
637 | 641 | Subclassing forms |
638 | 642 | ----------------- |
639 | 643 | |
640 | | If you have multiple ``Form`` classes that share fields, you can use |
| 644 | If you have multiple :class:`Form` classes that share fields, you can use |
641 | 645 | subclassing to remove redundancy. |
642 | 646 | |
643 | | When you subclass a custom ``Form`` class, the resulting subclass will |
| 647 | When you subclass a custom :class:`Form` class, the resulting subclass will |
644 | 648 | include all fields of the parent class(es), followed by the fields you define |
645 | 649 | in the subclass. |
646 | 650 | |
… |
… |
|
685 | 689 | .. attribute:: Form.prefix |
686 | 690 | |
687 | 691 | You can put several Django forms inside one ``<form>`` tag. To give each |
688 | | ``Form`` its own namespace, use the ``prefix`` keyword argument:: |
| 692 | :class:`Form` its own namespace, use the ``prefix`` keyword argument:: |
689 | 693 | |
690 | 694 | >>> mother = PersonForm(prefix="mother") |
691 | 695 | >>> father = PersonForm(prefix="father") |
-
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
a
|
b
|
|
726 | 726 | .. attribute:: URLField.validator_user_agent |
727 | 727 | |
728 | 728 | String used as the user-agent used when checking for a URL's existence. |
729 | | Defaults to the value of the ``URL_VALIDATOR_USER_AGENT`` setting. |
| 729 | Defaults to the value of the :setting:`URL_VALIDATOR_USER_AGENT` setting. |
730 | 730 | |
731 | 731 | Slightly complex built-in ``Field`` classes |
732 | 732 | ------------------------------------------- |
-
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 | |
… |
… |
|
186 | 186 | page. This lets you override the default template name (see below). |
187 | 187 | |
188 | 188 | * ``template_loader``: The template loader to use when loading the |
189 | | template. By default, it's ``django.template.loader``. |
| 189 | template. By default, it's :mod:`django.template.loader`. |
190 | 190 | |
191 | 191 | * ``extra_context``: A dictionary of values to add to the template |
192 | 192 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
202 | 202 | the view's template. |
203 | 203 | |
204 | 204 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
205 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 205 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
206 | 206 | |
207 | 207 | * ``allow_future``: A boolean specifying whether to include "future" |
208 | 208 | objects on this page, where "future" means objects in which the field |
… |
… |
|
271 | 271 | page. This lets you override the default template name (see below). |
272 | 272 | |
273 | 273 | * ``template_loader``: The template loader to use when loading the |
274 | | template. By default, it's ``django.template.loader``. |
| 274 | template. By default, it's :mod:`django.template.loader`. |
275 | 275 | |
276 | 276 | * ``extra_context``: A dictionary of values to add to the template |
277 | 277 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
299 | 299 | this is ``False``. |
300 | 300 | |
301 | 301 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
302 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 302 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
303 | 303 | |
304 | 304 | * ``allow_future``: A boolean specifying whether to include "future" |
305 | 305 | objects on this page, where "future" means objects in which the field |
… |
… |
|
365 | 365 | page. This lets you override the default template name (see below). |
366 | 366 | |
367 | 367 | * ``template_loader``: The template loader to use when loading the |
368 | | template. By default, it's ``django.template.loader``. |
| 368 | template. By default, it's :mod:`django.template.loader`. |
369 | 369 | |
370 | 370 | * ``extra_context``: A dictionary of values to add to the template |
371 | 371 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
386 | 386 | determining the variable's name. |
387 | 387 | |
388 | 388 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
389 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 389 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
390 | 390 | |
391 | 391 | * ``allow_future``: A boolean specifying whether to include "future" |
392 | 392 | objects on this page, where "future" means objects in which the field |
… |
… |
|
446 | 446 | page. This lets you override the default template name (see below). |
447 | 447 | |
448 | 448 | * ``template_loader``: The template loader to use when loading the |
449 | | template. By default, it's ``django.template.loader``. |
| 449 | template. By default, it's :mod:`django.template.loader`. |
450 | 450 | |
451 | 451 | * ``extra_context``: A dictionary of values to add to the template |
452 | 452 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
467 | 467 | determining the variable's name. |
468 | 468 | |
469 | 469 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
470 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 470 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
471 | 471 | |
472 | 472 | * ``allow_future``: A boolean specifying whether to include "future" |
473 | 473 | objects on this page, where "future" means objects in which the field |
… |
… |
|
531 | 531 | page. This lets you override the default template name (see below). |
532 | 532 | |
533 | 533 | * ``template_loader``: The template loader to use when loading the |
534 | | template. By default, it's ``django.template.loader``. |
| 534 | template. By default, it's :mod:`django.template.loader`. |
535 | 535 | |
536 | 536 | * ``extra_context``: A dictionary of values to add to the template |
537 | 537 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
552 | 552 | determining the variable's name. |
553 | 553 | |
554 | 554 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
555 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 555 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
556 | 556 | |
557 | 557 | * ``allow_future``: A boolean specifying whether to include "future" |
558 | 558 | objects on this page, where "future" means objects in which the field |
… |
… |
|
648 | 648 | It's a bit of a brain-bender, but it's useful in some cases. |
649 | 649 | |
650 | 650 | * ``template_loader``: The template loader to use when loading the |
651 | | template. By default, it's ``django.template.loader``. |
| 651 | template. By default, it's :mod:`django.template.loader`. |
652 | 652 | |
653 | 653 | * ``extra_context``: A dictionary of values to add to the template |
654 | 654 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
662 | 662 | to use in the template context. By default, this is ``'object'``. |
663 | 663 | |
664 | 664 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
665 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 665 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
666 | 666 | |
667 | 667 | * ``allow_future``: A boolean specifying whether to include "future" |
668 | 668 | objects on this page, where "future" means objects in which the field |
… |
… |
|
717 | 717 | page. This lets you override the default template name (see below). |
718 | 718 | |
719 | 719 | * ``template_loader``: The template loader to use when loading the |
720 | | template. By default, it's ``django.template.loader``. |
| 720 | template. By default, it's :mod:`django.template.loader`. |
721 | 721 | |
722 | 722 | * ``extra_context``: A dictionary of values to add to the template |
723 | 723 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
738 | 738 | determining the variable's name. |
739 | 739 | |
740 | 740 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
741 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 741 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
742 | 742 | |
743 | 743 | **Template name:** |
744 | 744 | |
… |
… |
|
843 | 843 | It's a bit of a brain-bender, but it's useful in some cases. |
844 | 844 | |
845 | 845 | * ``template_loader``: The template loader to use when loading the |
846 | | template. By default, it's ``django.template.loader``. |
| 846 | template. By default, it's :mod:`django.template.loader`. |
847 | 847 | |
848 | 848 | * ``extra_context``: A dictionary of values to add to the template |
849 | 849 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
857 | 857 | to use in the template context. By default, this is ``'object'``. |
858 | 858 | |
859 | 859 | * ``mimetype``: The MIME type to use for the resulting document. Defaults |
860 | | to the value of the ``DEFAULT_CONTENT_TYPE`` setting. |
| 860 | to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting. |
861 | 861 | |
862 | 862 | **Template name:** |
863 | 863 | |
… |
… |
|
926 | 926 | page. This lets you override the default template name (see below). |
927 | 927 | |
928 | 928 | * ``template_loader``: The template loader to use when loading the |
929 | | template. By default, it's ``django.template.loader``. |
| 929 | template. By default, it's :mod:`django.template.loader`. |
930 | 930 | |
931 | 931 | * ``extra_context``: A dictionary of values to add to the template |
932 | 932 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
1011 | 1011 | page. This lets you override the default template name (see below). |
1012 | 1012 | |
1013 | 1013 | * ``template_loader``: The template loader to use when loading the |
1014 | | template. By default, it's ``django.template.loader``. |
| 1014 | template. By default, it's :mod:`django.template.loader`. |
1015 | 1015 | |
1016 | 1016 | * ``extra_context``: A dictionary of values to add to the template |
1017 | 1017 | context. By default, this is an empty dictionary. If a value in the |
… |
… |
|
1093 | 1093 | page. This lets you override the default template name (see below). |
1094 | 1094 | |
1095 | 1095 | * ``template_loader``: The template loader to use when loading the |
1096 | | template. By default, it's ``django.template.loader``. |
| 1096 | template. By default, it's :mod:`django.template.loader`. |
1097 | 1097 | |
1098 | 1098 | * ``extra_context``: A dictionary of values to add to the template |
1099 | 1099 | 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
|
|
14 | 14 | |
15 | 15 | When a page is requested, Django creates an :class:`HttpRequest` object that |
16 | 16 | contains metadata about the request. Then Django loads the appropriate view, |
17 | | passing the :class:`HttpRequest` as the first argument to the view function. Each |
18 | | view is responsible for returning an :class:`HttpResponse` object. |
| 17 | passing the :class:`HttpRequest` as the first argument to the view function. |
| 18 | Each view is responsible for returning an :class:`HttpResponse` object. |
19 | 19 | |
20 | | This document explains the APIs for :class:`HttpRequest` and :class:`HttpResponse` |
21 | | objects. |
| 20 | This document explains the APIs for :class:`HttpRequest` and |
| 21 | :class:`HttpResponse` objects. |
22 | 22 | |
23 | 23 | HttpRequest objects |
24 | 24 | =================== |
… |
… |
|
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). |
56 | | You can write to this attribute to change the encoding used when accessing |
57 | | the form data. Any subsequent attribute accesses (such as reading from |
58 | | ``GET`` or ``POST``) will use the new ``encoding`` value. Useful if you |
59 | | know the form data is not in the ``DEFAULT_CHARSET`` encoding. |
| 55 | data (or ``None``, which means the :setting:`DEFAULT_CHARSET` setting is |
| 56 | used). You can write to this attribute to change the encoding used when |
| 57 | accessing the form data. Any subsequent attribute accesses (such as reading |
| 58 | from ``GET`` or ``POST``) will use the new ``encoding`` value. Useful if |
| 59 | you know the form data is not in the ``DEFAULT_CHARSET`` encoding. |
60 | 60 | |
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 |
101 | | attributes: |
| 100 | value in ``FILES`` is an :class:`UploadedFile` object containing the |
| 101 | following attributes: |
102 | 102 | |
103 | 103 | * ``read(num_bytes=None)`` -- Read a number of bytes from the file. |
104 | 104 | * ``name`` -- The name of the uploaded file. |
105 | 105 | * ``size`` -- The size, in bytes, of the uploaded file. |
106 | | * ``chunks(chunk_size=None)`` -- A generator that yields sequential chunks of data. |
| 106 | * ``chunks(chunk_size=None)`` -- A generator that yields sequential |
| 107 | chunks of data. |
107 | 108 | |
108 | 109 | See :ref:`topics-files` for more information. |
109 | 110 | |
… |
… |
|
151 | 152 | |
152 | 153 | .. attribute:: HttpRequest.user |
153 | 154 | |
154 | | A ``django.contrib.auth.models.User`` object representing the currently |
| 155 | A :class:`django.contrib.auth.models.User` object representing the currently |
155 | 156 | 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:: |
| 157 | to an instance of :class:`django.contrib.auth.models.AnonymousUser`. You |
| 158 | can tell them apart with :meth:`is_authenticated`, like so:: |
158 | 159 | |
159 | 160 | if request.user.is_authenticated(): |
160 | 161 | # Do something for logged-in users. |
… |
… |
|
181 | 182 | |
182 | 183 | Not defined by Django itself, but will be read if other code (e.g., a custom |
183 | 184 | middleware class) sets it. When present, this will be used as the root |
184 | | URLconf for the current request, overriding the ``ROOT_URLCONF`` setting. |
185 | | See :ref:`how-django-processes-a-request` for details. |
| 185 | URLconf for the current request, overriding the :setting:`ROOT_URLCONF` |
| 186 | setting. See :ref:`how-django-processes-a-request` for details. |
186 | 187 | |
187 | 188 | Methods |
188 | 189 | ------- |
… |
… |
|
228 | 229 | |
229 | 230 | .. versionadded:: 1.0 |
230 | 231 | |
231 | | Returns ``True`` if the request was made via an ``XMLHttpRequest``, by checking |
232 | | the ``HTTP_X_REQUESTED_WITH`` header for the string ``'XMLHttpRequest'``. The |
233 | | following major JavaScript libraries all send this header: |
| 232 | Returns ``True`` if the request was made via an ``XMLHttpRequest``, by |
| 233 | checking the ``HTTP_X_REQUESTED_WITH`` header for the string |
| 234 | ``'XMLHttpRequest'``. The following major JavaScript libraries all send this |
| 235 | header: |
234 | 236 | |
235 | 237 | * jQuery |
236 | 238 | * Dojo |
… |
… |
|
248 | 250 | |
249 | 251 | .. class:: QueryDict |
250 | 252 | |
251 | | In an :class:`HttpRequest` object, the ``GET`` and ``POST`` attributes are instances |
252 | | of ``django.http.QueryDict``. :class:`QueryDict` is a dictionary-like |
253 | | class customized to deal with multiple values for the same key. This is |
254 | | necessary because some HTML form elements, notably |
255 | | ``<select multiple="multiple">``, pass multiple values for the same key. |
| 253 | In an :class:`HttpRequest` object, the ``GET`` and ``POST`` attributes are |
| 254 | instances of ``django.http.QueryDict``. ``QueryDict`` is a dictionary-like class |
| 255 | customized to deal with multiple values for the same key. This is necessary |
| 256 | because some HTML form elements, notably ``<select multiple="multiple">``, pass |
| 257 | multiple values for the same key. |
256 | 258 | |
257 | 259 | ``QueryDict`` instances are immutable, unless you create a ``copy()`` of them. |
258 | 260 | That means you can't change attributes of ``request.POST`` and ``request.GET`` |
… |
… |
|
261 | 263 | Methods |
262 | 264 | ------- |
263 | 265 | |
264 | | :class:`QueryDict` implements all the standard dictionary methods, because it's |
| 266 | ``QueryDict`` implements all the standard dictionary methods, because it's |
265 | 267 | a subclass of dictionary. Exceptions are outlined here: |
266 | 268 | |
267 | 269 | .. method:: QueryDict.__getitem__(key) |
… |
… |
|
294 | 296 | Just like the standard dictionary ``setdefault()`` method, except it uses |
295 | 297 | ``__setitem__`` internally. |
296 | 298 | |
297 | | .. method:: QueryDict.update(other_dict) |
| 299 | .. method:: QueryDict.update(other_dict) |
298 | 300 | |
299 | 301 | Takes either a ``QueryDict`` or standard dictionary. Just like the standard |
300 | 302 | dictionary ``update()`` method, except it *appends* to the current |
… |
… |
|
357 | 359 | |
358 | 360 | Like :meth:`items()`, except it includes all values, as a list, for each |
359 | 361 | member of the dictionary. For example:: |
360 | | |
| 362 | |
361 | 363 | >>> q = QueryDict('a=1&a=2&a=3') |
362 | 364 | >>> q.lists() |
363 | 365 | [('a', ['1', '2', '3'])] |
364 | | |
| 366 | |
365 | 367 | .. method:: QueryDict.urlencode() |
366 | 368 | |
367 | 369 | Returns a string of the data in query-string format. |
… |
… |
|
373 | 375 | .. class:: HttpResponse |
374 | 376 | |
375 | 377 | In contrast to :class:`HttpRequest` objects, which are created automatically by |
376 | | Django, :class:`HttpResponse` objects are your responsibility. Each view you |
| 378 | Django, ``HttpResponse`` objects are your responsibility. Each view you |
377 | 379 | write is responsible for instantiating, populating and returning an |
378 | | :class:`HttpResponse`. |
| 380 | ``HttpResponse``. |
379 | 381 | |
380 | | The :class:`HttpResponse` class lives in the ``django.http`` module. |
| 382 | The ``HttpResponse`` class lives in the :mod:`django.http` module. |
381 | 383 | |
382 | 384 | Usage |
383 | 385 | ----- |
… |
… |
|
386 | 388 | ~~~~~~~~~~~~~~~ |
387 | 389 | |
388 | 390 | Typical usage is to pass the contents of the page, as a string, to the |
389 | | :class:`HttpResponse` constructor:: |
| 391 | ``HttpResponse`` constructor:: |
390 | 392 | |
391 | 393 | >>> response = HttpResponse("Here's the text of the Web page.") |
392 | 394 | >>> response = HttpResponse("Text only, please.", mimetype="text/plain") |
… |
… |
|
415 | 417 | hard-coded strings. If you use this technique, follow these guidelines: |
416 | 418 | |
417 | 419 | * 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 |
| 420 | * If an ``HttpResponse`` has been initialized with an iterator as its |
| 421 | content, you can't use the ``HttpResponse`` instance as a file-like |
420 | 422 | object. Doing so will raise ``Exception``. |
421 | 423 | |
422 | 424 | Setting headers |
… |
… |
|
452 | 454 | ------- |
453 | 455 | |
454 | 456 | .. method:: HttpResponse.__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE) |
455 | | |
| 457 | |
456 | 458 | Instantiates an ``HttpResponse`` object with the given page content (a |
457 | | string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``. |
| 459 | string) and MIME type. The :setting:`DEFAULT_CONTENT_TYPE` is ``'text/html'``. |
458 | 460 | |
459 | 461 | ``content`` can be an iterator or a string. If it's an iterator, it should |
460 | 462 | return strings, and those strings will be joined together to form the |
… |
… |
|
470 | 472 | encoding, which makes it more than just a MIME type specification. |
471 | 473 | If ``mimetype`` is specified (not ``None``), that value is used. |
472 | 474 | Otherwise, ``content_type`` is used. If neither is given, the |
473 | | ``DEFAULT_CONTENT_TYPE`` setting is used. |
| 475 | :setting:`DEFAULT_CONTENT_TYPE` setting is used. |
474 | 476 | |
475 | 477 | .. method:: HttpResponse.__setitem__(header, value) |
476 | 478 | |
… |
… |
|
519 | 521 | |
520 | 522 | .. method:: HttpResponse.write(content) |
521 | 523 | |
522 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 524 | This method makes an ``HttpResponse`` instance a file-like object. |
523 | 525 | |
524 | 526 | .. method:: HttpResponse.flush() |
525 | 527 | |
526 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 528 | This method makes an ``HttpResponse`` instance a file-like object. |
527 | 529 | |
528 | 530 | .. method:: HttpResponse.tell() |
529 | 531 | |
530 | | This method makes an :class:`HttpResponse` instance a file-like object. |
| 532 | This method makes an ``HttpResponse`` instance a file-like object. |
531 | 533 | |
532 | 534 | .. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 |
533 | 535 | |
… |
… |
|
537 | 539 | HttpResponse subclasses |
538 | 540 | ----------------------- |
539 | 541 | |
540 | | Django includes a number of ``HttpResponse`` subclasses that handle different |
541 | | types of HTTP responses. Like ``HttpResponse``, these subclasses live in |
542 | | :mod:`django.http`. |
| 542 | Django includes a number of :class:`HttpResponse` subclasses that handle |
| 543 | different types of HTTP responses. Like ``HttpResponse``, these subclasses live |
| 544 | in :mod:`django.http`. |
543 | 545 | |
544 | 546 | .. class:: HttpResponseRedirect |
545 | 547 | |
546 | | The constructor takes a single argument -- the path to redirect to. This |
547 | | can be a fully qualified URL (e.g. ``'http://www.yahoo.com/search/'``) or an |
548 | | absolute URL with no domain (e.g. ``'/search/'``). Note that this returns |
549 | | an HTTP status code 302. |
| 548 | The constructor takes a single argument -- the path to redirect to. This can |
| 549 | be a fully qualified URL (e.g. ``'http://www.yahoo.com/search/'``) or an |
| 550 | absolute URL with no domain (e.g. ``'/search/'``). Note that this returns an |
| 551 | HTTP status code 302. |
550 | 552 | |
551 | 553 | .. class:: HttpResponsePermanentRedirect |
552 | 554 | |
-
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
|
|
1587 | 1587 | ------------------------------- |
1588 | 1588 | |
1589 | 1589 | Django comes with a couple of other template-tag libraries that you have to |
1590 | | enable explicitly in your ``INSTALLED_APPS`` setting and enable in your |
| 1590 | enable explicitly in your :setting:`INSTALLED_APPS` setting and enable in your |
1591 | 1591 | template with the ``{% load %}`` tag. |
1592 | 1592 | |
1593 | 1593 | 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``. |
… |
… |
|
693 | 693 | |
694 | 694 | .. function:: views.login() |
695 | 695 | |
696 | | Here's what ``django.contrib.auth.views.login`` does: |
| 696 | Here's what :func:`django.contrib.auth.views.login` does: |
697 | 697 | |
698 | 698 | * If called via ``GET``, it displays a login form that POSTs to the |
699 | 699 | same URL. More on this in a bit. |
… |
… |
|
1037 | 1037 | Default permissions |
1038 | 1038 | ------------------- |
1039 | 1039 | |
1040 | | When ``django.contrib.auth`` is listed in your :setting:`INSTALLED_APPS` |
| 1040 | When :mod:`django.contrib.auth` is listed in your :setting:`INSTALLED_APPS` |
1041 | 1041 | setting, it will ensure that three default permissions -- add, change and |
1042 | 1042 | delete -- are created for each Django model defined in one of your installed |
1043 | 1043 | applications. |
1044 | 1044 | |
1045 | 1045 | These permissions will be created when you run :djadmin:`manage.py syncdb |
1046 | 1046 | <syncdb>`; the first time you run ``syncdb`` after adding |
1047 | | ``django.contrib.auth`` to :setting:`INSTALLED_APPS`, the default permissions |
| 1047 | :mod:`django.contrib.auth` to :setting:`INSTALLED_APPS`, the default permissions |
1048 | 1048 | will be created for all previously-installed models, as well as for any new |
1049 | 1049 | models being installed at that time. Afterward, it will create default |
1050 | 1050 | permissions for new models each time you run :djadmin:`manage.py syncdb |
-
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 |
53 | | file. Here's an explanation of all available values for CACHE_BACKEND. |
| 52 | Your cache preference goes in the :setting:`CACHE_BACKEND` setting in your |
| 53 | settings file. Here's an explanation of all available values for CACHE_BACKEND. |
54 | 54 | |
55 | 55 | Memcached |
56 | 56 | --------- |
… |
… |
|
81 | 81 | "Client APIs" section. |
82 | 82 | |
83 | 83 | .. versionadded:: 1.0 |
| 84 | |
84 | 85 | The ``cmemcache`` option is new in 1.0. Previously, only |
85 | 86 | ``python-memcached`` was supported. |
86 | 87 | |
87 | | To use Memcached with Django, set ``CACHE_BACKEND`` to |
| 88 | To use Memcached with Django, set :setting:`CACHE_BACKEND` to |
88 | 89 | ``memcached://ip:port/``, where ``ip`` is the IP address of the Memcached |
89 | 90 | daemon and ``port`` is the port on which Memcached is running. |
90 | 91 | |
… |
… |
|
94 | 95 | |
95 | 96 | One excellent feature of Memcached is its ability to share cache over multiple |
96 | 97 | servers. To take advantage of this feature, include all server addresses in |
97 | | ``CACHE_BACKEND``, separated by semicolons. In this example, the cache is |
| 98 | :setting:`CACHE_BACKEND`, separated by semicolons. In this example, the cache is |
98 | 99 | shared over Memcached instances running on IP address 172.19.26.240 and |
99 | 100 | 172.19.26.242, both on port 11211:: |
100 | 101 | |
… |
… |
|
122 | 123 | in your database that is in the proper format that Django's database-cache |
123 | 124 | system expects. |
124 | 125 | |
125 | | Once you've created that database table, set your ``CACHE_BACKEND`` setting to |
126 | | ``"db://tablename"``, where ``tablename`` is the name of the database table. |
127 | | In this example, the cache table's name is ``my_cache_table``:: |
| 126 | Once you've created that database table, set your :setting:`CACHE_BACKEND` |
| 127 | setting to ``"db://tablename"``, where ``tablename`` is the name of the database |
| 128 | table. In this example, the cache table's name is ``my_cache_table``:: |
128 | 129 | |
129 | 130 | CACHE_BACKEND = 'db://my_cache_table' |
130 | 131 | |
… |
… |
|
134 | 135 | ------------------ |
135 | 136 | |
136 | 137 | 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``, |
138 | | use this setting:: |
| 138 | :setting:`CACHE_BACKEND`. For example, to store cached data in |
| 139 | ``/var/tmp/django_cache``, use this setting:: |
139 | 140 | |
140 | 141 | CACHE_BACKEND = 'file:///var/tmp/django_cache' |
141 | 142 | |
… |
… |
|
158 | 159 | |
159 | 160 | If you want the speed advantages of in-memory caching but don't have the |
160 | 161 | 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 |
162 | | ``"locmem:///"``. For example:: |
| 162 | cache is multi-process and thread-safe. To use it, set :setting:`CACHE_BACKEND` |
| 163 | to ``"locmem:///"``. For example:: |
163 | 164 | |
164 | 165 | CACHE_BACKEND = 'locmem:///' |
165 | | |
| 166 | |
166 | 167 | Note that each process will have its own private cache instance, which means no |
167 | 168 | cross-process caching is possible. This obviously also means the local memory |
168 | 169 | cache isn't particularly memory-efficient, so it's probably not a good choice |
… |
… |
|
178 | 179 | various places but a development/test environment on which you don't want to |
179 | 180 | cache. As a result, your development environment won't use caching and your |
180 | 181 | production environment still will. To activate dummy caching, set |
181 | | ``CACHE_BACKEND`` like so:: |
| 182 | :setting:`CACHE_BACKEND` like so:: |
182 | 183 | |
183 | 184 | CACHE_BACKEND = 'dummy:///' |
184 | 185 | |
… |
… |
|
190 | 191 | While Django includes support for a number of cache backends out-of-the-box, |
191 | 192 | sometimes you might want to use a customized cache backend. To use an external |
192 | 193 | 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:: |
| 194 | part before the initial colon) of the :setting:`CACHE_BACKEND` URI, like so:: |
194 | 195 | |
195 | 196 | CACHE_BACKEND = 'path.to.backend://' |
196 | 197 | |
… |
… |
|
206 | 207 | ----------------------- |
207 | 208 | |
208 | 209 | All caches may take arguments. They're given in query-string style on the |
209 | | ``CACHE_BACKEND`` setting. Valid arguments are: |
| 210 | :setting:`CACHE_BACKEND` setting. Valid arguments are: |
210 | 211 | |
211 | 212 | timeout |
212 | 213 | Default timeout, in seconds, to use for the cache. Defaults to 5 |
… |
… |
|
241 | 242 | ================== |
242 | 243 | |
243 | 244 | .. versionchanged:: 1.0 |
244 | | (previous versions of Django only provided a single ``CacheMiddleware`` instead |
245 | | of the two pieces described below). |
| 245 | |
| 246 | (previous versions of Django only provided a single ``CacheMiddleware`` |
| 247 | instead of the two pieces described below). |
246 | 248 | |
247 | 249 | Once the cache is set up, the simplest way to use caching is to cache your |
248 | 250 | entire site. You'll need to add |
249 | 251 | ``'django.middleware.cache.UpdateCacheMiddleware'`` and |
250 | 252 | ``'django.middleware.cache.FetchFromCacheMiddleware'`` to your |
251 | | ``MIDDLEWARE_CLASSES`` setting, as in this example:: |
| 253 | :setting:`MIDDLEWARE_CLASSES` setting, as in this example:: |
252 | 254 | |
253 | 255 | MIDDLEWARE_CLASSES = ( |
254 | 256 | 'django.middleware.cache.UpdateCacheMiddleware', |
… |
… |
|
264 | 266 | |
265 | 267 | Then, add the following required settings to your Django settings file: |
266 | 268 | |
267 | | * ``CACHE_MIDDLEWARE_SECONDS`` -- The number of seconds each page should be |
268 | | cached. |
269 | | * ``CACHE_MIDDLEWARE_KEY_PREFIX`` -- If the cache is shared across multiple |
270 | | sites using the same Django installation, set this to the name of the site, |
271 | | or some other string that is unique to this Django instance, to prevent key |
272 | | collisions. Use an empty string if you don't care. |
| 269 | * :setting:`CACHE_MIDDLEWARE_SECONDS` -- The number of seconds each page should |
| 270 | be cached. |
| 271 | * :setting:`CACHE_MIDDLEWARE_KEY_PREFIX` -- If the cache is shared across |
| 272 | multiple sites using the same Django installation, set this to the name of |
| 273 | the site, or some other string that is unique to this Django instance, to |
| 274 | prevent key collisions. Use an empty string if you don't care. |
273 | 275 | |
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 |
| 276 | The cache middleware caches every page that doesn't have GET or POST parameters. |
| 277 | Optionally, if the :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY` setting is |
276 | 278 | ``True``, only anonymous requests (i.e., not those made by a logged-in user) |
277 | 279 | will be cached. This is a simple and effective way of disabling caching for any |
278 | 280 | 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 |
280 | | ``AuthenticationMiddleware``. |
| 281 | :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY`, you should make sure you've |
| 282 | activated ``AuthenticationMiddleware``. |
281 | 283 | |
282 | 284 | Additionally, the cache middleware automatically sets a few headers in each |
283 | 285 | ``HttpResponse``: |
… |
… |
|
285 | 287 | * Sets the ``Last-Modified`` header to the current date/time when a fresh |
286 | 288 | (uncached) version of the page is requested. |
287 | 289 | * Sets the ``Expires`` header to the current date/time plus the defined |
288 | | ``CACHE_MIDDLEWARE_SECONDS``. |
| 290 | :setting:`CACHE_MIDDLEWARE_SECONDS`. |
289 | 291 | * Sets the ``Cache-Control`` header to give a max age for the page -- again, |
290 | | from the ``CACHE_MIDDLEWARE_SECONDS`` setting. |
| 292 | from the :setting:`CACHE_MIDDLEWARE_SECONDS` setting. |
291 | 293 | |
292 | 294 | See :ref:`topics-http-middleware` for more on middleware. |
293 | 295 | |
… |
… |
|
295 | 297 | |
296 | 298 | If a view sets its own cache expiry time (i.e. it has a ``max-age`` section in |
297 | 299 | 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 |
| 300 | time, rather than :setting:`CACHE_MIDDLEWARE_SECONDS`. Using the decorators in |
| 301 | :mod:`django.views.decorators.cache` you can easily set a view's expiry time |
300 | 302 | (using the ``cache_control`` decorator) or disable caching for a view (using |
301 | 303 | the ``never_cache`` decorator). See the `using other headers`__ section for |
302 | 304 | more on these decorators. |
… |
… |
|
307 | 309 | ================== |
308 | 310 | |
309 | 311 | 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`` |
| 312 | individual views. :mod:`django.views.decorators.cache` defines a ``cache_page`` |
311 | 313 | decorator that will automatically cache the view's response for you. It's easy |
312 | 314 | to use:: |
313 | 315 | |
… |
… |
|
347 | 349 | {% endcache %} |
348 | 350 | |
349 | 351 | Sometimes you might want to cache multiple copies of a fragment depending on |
350 | | some dynamic data that appears inside the fragment. For example, you might want a |
351 | | separate cached copy of the sidebar used in the previous example for every user |
352 | | of your site. Do this by passing additional arguments to the ``{% cache %}`` |
353 | | template tag to uniquely identify the cache fragment:: |
| 352 | some dynamic data that appears inside the fragment. For example, you might want |
| 353 | a separate cached copy of the sidebar used in the previous example for every |
| 354 | user of your site. Do this by passing additional arguments to the ``{% cache |
| 355 | %}`` template tag to uniquely identify the cache fragment:: |
354 | 356 | |
355 | 357 | {% load cache %} |
356 | 358 | {% cache 500 sidebar request.user.username %} |
… |
… |
|
379 | 381 | intensive database query. In cases like this, you can use the low-level cache |
380 | 382 | API to store objects in the cache with any level of granularity you like. |
381 | 383 | |
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`` |
| 384 | The cache API is simple. The cache module, :mod:`django.core.cache`, exports a |
| 385 | ``cache`` object that's automatically created from the :setting:`CACHE_BACKEND` |
384 | 386 | setting:: |
385 | 387 | |
386 | 388 | >>> from django.core.cache import cache |
… |
… |
|
392 | 394 | 'hello, world!' |
393 | 395 | |
394 | 396 | The ``timeout_seconds`` argument is optional and defaults to the ``timeout`` |
395 | | argument in the ``CACHE_BACKEND`` setting (explained above). |
| 397 | argument in the :setting:`CACHE_BACKEND` setting (explained above). |
396 | 398 | |
397 | 399 | If the object doesn't exist in the cache, ``cache.get()`` returns ``None``:: |
398 | 400 | |
… |
… |
|
618 | 620 | For explanation of Cache-Control HTTP directives, see the `Cache-Control spec`_. |
619 | 621 | |
620 | 622 | (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 |
622 | | ``max_age`` in a ``cache_control`` decorator, the decorator will take |
| 623 | the value of the :setting:`CACHE_MIDDLEWARE_SETTINGS` setting. If you use a |
| 624 | custom ``max_age`` in a ``cache_control`` decorator, the decorator will take |
623 | 625 | precedence, and the header values will be merged correctly.) |
624 | 626 | |
625 | 627 | If you want to use headers to disable caching altogether, |
626 | 628 | ``django.views.decorators.cache.never_cache`` is a view decorator that adds |
627 | | headers to ensure the response won't be cached by browsers or other caches. Example:: |
| 629 | headers to ensure the response won't be cached by browsers or other caches. |
| 630 | Example:: |
628 | 631 | |
629 | 632 | from django.views.decorators.cache import never_cache |
630 | 633 | @never_cache |
… |
… |
|
650 | 653 | =========================== |
651 | 654 | |
652 | 655 | 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 |
| 656 | place within the :setting:`MIDDLEWARE_CLASSES` setting. That's because the cache |
654 | 657 | middleware needs to know which headers by which to vary the cache storage. |
655 | 658 | Middleware always adds something to the ``Vary`` response header when it can. |
656 | 659 | |
-
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 |
| 140 | file. |
140 | 141 | |
141 | 142 | If you do this, Django won't provide any automatic transaction management |
142 | 143 | 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 |
52 | | you're not required to be using internationalization features to use this |
| 51 | :mod:`django.utils` helper functions and Django's internationalization hooks |
| 52 | (but you're not required to be using internationalization features to use this |
53 | 53 | library). |
54 | 54 | |
55 | 55 | Form objects |
-
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
|
|
136 | 136 | |
137 | 137 | Defaults to your system's standard temporary directory (i.e. ``/tmp`` on |
138 | 138 | most Unix-like systems). |
139 | | |
| 139 | |
140 | 140 | :setting:`FILE_UPLOAD_PERMISSIONS` |
141 | 141 | The numeric mode (i.e. ``0644``) to set newly uploaded files to. For |
142 | 142 | more information about what these modes mean, see the `documentation for |
143 | 143 | os.chmod`_ |
144 | | |
| 144 | |
145 | 145 | If this isn't given or is ``None``, you'll get operating-system |
146 | 146 | dependent behavior. On most platforms, temporary files will have a mode |
147 | 147 | of ``0600``, and files saved from memory will be saved using the |
148 | 148 | system's standard umask. |
149 | | |
| 149 | |
150 | 150 | .. warning:: |
151 | | |
| 151 | |
152 | 152 | If you're not familiar with file modes, please note that the leading |
153 | 153 | ``0`` is very important: it indicates an octal number, which is the |
154 | 154 | way that modes must be specified. If you try to use ``644``, you'll |
… |
… |
|
169 | 169 | Which means "try to upload to memory first, then fall back to temporary |
170 | 170 | files." |
171 | 171 | |
172 | | .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html |
| 172 | .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html |
173 | 173 | |
174 | 174 | ``UploadedFile`` objects |
175 | 175 | ======================== |
… |
… |
|
193 | 193 | ``UploadedFile.temporary_file_path()`` |
194 | 194 | Only files uploaded onto disk will have this method; it returns the full |
195 | 195 | path to the temporary uploaded file. |
196 | | |
| 196 | |
197 | 197 | .. note:: |
198 | 198 | |
199 | 199 | Like regular Python files, you can read the file line-by-line simply by |
200 | 200 | iterating over the uploaded file: |
201 | | |
| 201 | |
202 | 202 | .. code-block:: python |
203 | | |
| 203 | |
204 | 204 | for line in uploadedfile: |
205 | 205 | do_something_with(line) |
206 | | |
| 206 | |
207 | 207 | However, *unlike* standard Python files, :class:`UploadedFile` only |
208 | 208 | understands ``\n`` (also known as "Unix-style") line endings. If you know |
209 | 209 | that you need to handle uploaded files with different line endings, you'll |
… |
… |
|
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 |
218 | | defaults to:: |
| 217 | handlers are initially defined in the :setting:`FILE_UPLOAD_HANDLERS` setting, |
| 218 | which defaults to:: |
219 | 219 | |
220 | 220 | ("django.core.files.uploadhandler.MemoryFileUploadHandler", |
221 | 221 | "django.core.files.uploadhandler.TemporaryFileUploadHandler",) |
… |
… |
|
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 |
239 | | would any other list. |
| 238 | handlers given by :setting:`FILE_UPLOAD_HANDLERS`, but you can modify the list |
| 239 | as you would any other list. |
240 | 240 | |
241 | 241 | For instance, suppose you've written a ``ProgressBarUploadHandler`` that |
242 | 242 | provides feedback on upload progress to some sort of AJAX widget. You'd add this |
-
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'``. |
21 | | The default ``settings.py`` created by ``django-admin.py startproject`` has |
| 19 | * Edit the :setting:`MIDDLEWARE_CLASSES` setting and make sure |
| 20 | :setting:`MIDDLEWARE_CLASSES` contains |
| 21 | ``'django.contrib.sessions.middleware.SessionMiddleware'``. The default |
| 22 | ``settings.py`` created by ``django-admin.py startproject`` has |
22 | 23 | ``SessionMiddleware`` activated. |
23 | 24 | |
24 | | * Add ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting, |
25 | | and run ``manage.py syncdb`` to install the single database table |
| 25 | * Add ``'django.contrib.sessions'`` to your :setting:`INSTALLED_APPS` |
| 26 | setting, and run ``manage.py syncdb`` to install the single database table |
26 | 27 | that stores session data. |
27 | 28 | |
28 | 29 | .. versionchanged:: 1.0 |
| 30 | |
29 | 31 | This step is optional if you're not using the database session backend; |
30 | 32 | see `configuring the session engine`_. |
31 | 33 | |
32 | 34 | 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. |
| 35 | ``SessionMiddleware`` line from :setting:`MIDDLEWARE_CLASSES` and |
| 36 | ``'django.contrib.sessions'`` from your :setting:`INSTALLED_APPS`. It'll save |
| 37 | you a small bit of overhead. |
35 | 38 | |
36 | 39 | Configuring the session engine |
37 | 40 | ============================== |
… |
… |
|
46 | 49 | Using file-based sessions |
47 | 50 | ------------------------- |
48 | 51 | |
49 | | To use file-based sessions, set the ``SESSION_ENGINE`` setting to |
| 52 | To use file-based sessions, set the :setting:`SESSION_ENGINE` setting to |
50 | 53 | ``"django.contrib.sessions.backends.file"``. |
51 | 54 | |
52 | | You might also want to set the ``SESSION_FILE_PATH`` setting (which defaults |
53 | | to output from ``tempfile.gettempdir()``, most likely ``/tmp``) to control |
54 | | where Django stores session files. Be sure to check that your Web server has |
55 | | permissions to read and write to this location. |
| 55 | You might also want to set the :setting:`SESSION_FILE_PATH` setting (which |
| 56 | defaults to output from ``tempfile.gettempdir()``, most likely ``/tmp``) to |
| 57 | control where Django stores session files. Be sure to check that your Web server |
| 58 | has permissions to read and write to this location. |
56 | 59 | |
57 | 60 | Using cache-based sessions |
58 | 61 | -------------------------- |
59 | 62 | |
60 | | To store session data using Django's cache system, set ``SESSION_ENGINE`` |
| 63 | To store session data using Django's cache system, set :setting:`SESSION_ENGINE` |
61 | 64 | to ``"django.contrib.sessions.backends.cache"``. You'll want to make sure |
62 | 65 | you've configured your cache; see the :ref:`cache documentation <topics-cache>` for details. |
63 | 66 | |
… |
… |
|
110 | 113 | * ``clear()`` |
111 | 114 | |
112 | 115 | .. versionadded:: 1.0 |
| 116 | |
113 | 117 | ``setdefault()`` and ``clear()`` are new in this version. |
114 | 118 | |
115 | 119 | It also has these methods: |
… |
… |
|
169 | 173 | |
170 | 174 | Returns the number of seconds until this session expires. For sessions |
171 | 175 | with no custom expiration (or those set to expire at browser close), this |
172 | | will equal ``settings.SESSION_COOKIE_AGE``. |
| 176 | will equal :setting:`setting.SESSION_COOKIE_AGE<SESSION_COOKIE_AGE>`. |
173 | 177 | |
174 | 178 | * ``get_expiry_date()`` |
175 | 179 | |
… |
… |
|
177 | 181 | |
178 | 182 | Returns the date this session will expire. For sessions with no custom |
179 | 183 | expiration (or those set to expire at browser close), this will equal the |
180 | | date ``settings.SESSION_COOKIE_AGE`` seconds from now. |
| 184 | date :setting:`settings.SESSION_COOKIE_AGE<SESSION_COOKIE_AGE>` seconds |
| 185 | from now. |
181 | 186 | |
182 | 187 | * ``get_expire_at_browser_close()`` |
183 | 188 | |
… |
… |
|
280 | 285 | datetime.datetime(2005, 8, 20, 13, 35, 0) |
281 | 286 | >>> s.save() |
282 | 287 | |
283 | | If you're using the ``django.contrib.sessions.backends.db`` backend, each |
| 288 | If you're using the :mod:`django.contrib.sessions.backends.db` backend, each |
284 | 289 | session is just a normal Django model. The ``Session`` model is defined in |
285 | 290 | ``django/contrib/sessions/models.py``. Because it's a normal model, you can |
286 | 291 | access sessions using the normal Django database API:: |
… |
… |
|
324 | 329 | |
325 | 330 | request.session.modified = True |
326 | 331 | |
327 | | To change this default behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting |
328 | | to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save |
329 | | the session to the database on every single request. |
| 332 | To change this default behavior, set the :setting:`SESSION_SAVE_EVERY_REQUEST` |
| 333 | setting to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will |
| 334 | save the session to the database on every single request. |
330 | 335 | |
331 | 336 | Note that the session cookie is only sent when a session has been created or |
332 | 337 | modified. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, the session cookie |
… |
… |
|
339 | 344 | =============================================== |
340 | 345 | |
341 | 346 | You can control whether the session framework uses browser-length sessions vs. |
342 | | persistent sessions with the ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` setting. |
| 347 | persistent sessions with the :setting:`SESSION_EXPIRE_AT_BROWSER_CLOSE` setting. |
343 | 348 | |
344 | 349 | By default, ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` is set to ``False``, which |
345 | 350 | means session cookies will be stored in users' browsers for as long as |
346 | | ``SESSION_COOKIE_AGE``. Use this if you don't want people to have to log in |
| 351 | :setting:`SESSION_COOKIE_AGE`. Use this if you don't want people to have to log in |
347 | 352 | every time they open a browser. |
348 | 353 | |
349 | 354 | If ``SESSION_EXPIRE_AT_BROWSER_CLOSE`` is set to ``True``, Django will use |
… |
… |
|
377 | 382 | Settings |
378 | 383 | ======== |
379 | 384 | |
380 | | A few :ref:`Django settings <ref-settings>` give you control over session behavior: |
| 385 | A few :ref:`Django settings <ref-settings>` give you control over session |
| 386 | behavior: |
381 | 387 | |
382 | 388 | SESSION_ENGINE |
383 | 389 | -------------- |
384 | 390 | |
385 | 391 | .. versionadded:: 1.0 |
386 | 392 | |
387 | | Default: ``django.contrib.sessions.backends.db`` |
| 393 | Default: :mod:`django.contrib.sessions.backends.db` |
388 | 394 | |
389 | 395 | Controls where Django stores session data. Valid values are: |
390 | 396 | |
-
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
|
|
36 | 36 | When a user requests a page from your Django-powered site, this is the |
37 | 37 | algorithm the system follows to determine which Python code to execute: |
38 | 38 | |
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 |
| 39 | 1. Django determines the root URLconf module to use. Ordinarily, this is the |
| 40 | 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 |
… |
… |
|
49 | 49 | later.) |
50 | 50 | |
51 | 51 | .. admonition:: Django's Time Zone |
52 | | |
53 | | Django includes a ``TIME_ZONE`` setting that defaults to |
| 52 | |
| 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 |
| 169 | (e.g., :setting:`MEDIA_URL`). |
170 | 170 | |
171 | | * If ``DEBUG`` is set to ``True`` (in your settings module), then your 404 |
172 | | view will never be used, and the traceback will be displayed instead. |
| 171 | * If :setting:`DEBUG` is set to ``True`` (in your settings module), then |
| 172 | your 404 view will never be used, and the traceback will be displayed |
| 173 | instead. |
173 | 174 | |
174 | 175 | The 500 (server error) view |
175 | 176 | ---------------------------- |
… |
… |
|
190 | 191 | |
191 | 192 | handler500 = 'mysite.views.my_custom_error_view' |
192 | 193 | |
193 | | Behind the scenes, Django determines the error view by looking for ``handler500``. |
194 | | By default, URLconfs contain the following line:: |
| 194 | Behind the scenes, Django determines the error view by looking for |
| 195 | ``handler500``. By default, URLconfs contain the following line:: |
195 | 196 | |
196 | 197 | from django.conf.urls.defaults import * |
197 | 198 | |
-
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 |
596 | | should follow these guidelines: |
| 595 | to your :setting:`MIDDLEWARE_CLASSES` setting. Because middleware order matters, |
| 596 | you should follow these guidelines: |
597 | 597 | |
598 | 598 | * Make sure it's one of the first middlewares installed. |
599 | 599 | * It should come after ``SessionMiddleware``, because ``LocaleMiddleware`` |
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 |
666 | | previous bullet, it's OK to mark the languages as translation strings |
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 |
670 | | module in itself depends on the settings, and that would cause a circular |
671 | | import. |
| 665 | * If you define a custom :setting:`LANGUAGES` setting, as explained in the |
| 666 | previous bullet, it's OK to mark the languages as translation strings -- |
| 667 | but use a "dummy" ``ugettext()`` function, not the one in |
| 668 | :mod:`django.utils.translation`. You should *never* import |
| 669 | :mod:`django.utils.translation` from within your settings file, because |
| 670 | that module in itself depends on the settings, and that would cause a |
| 671 | circular import. |
672 | 672 | |
673 | 673 | The solution is to use a "dummy" ``ugettext()`` function. Here's a sample |
674 | 674 | settings file:: |
… |
… |
|
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 |
| 687 | runtime. |
687 | 688 | |
688 | 689 | * The ``LocaleMiddleware`` can only select languages for which there is a |
689 | 690 | Django-provided base translation. If you want to provide translations |
… |
… |
|
700 | 701 | Technical message IDs are easily recognized; they're all upper case. You |
701 | 702 | don't translate the message ID as with other messages, you provide the |
702 | 703 | correct local variant on the provided English value. For example, with |
703 | | ``DATETIME_FORMAT`` (or ``DATE_FORMAT`` or ``TIME_FORMAT``), this would |
704 | | be the format string that you want to use in your language. The format |
705 | | is identical to the format strings used by the ``now`` template tag. |
| 704 | :setting:`DATETIME_FORMAT` (or :setting:`DATE_FORMAT` or |
| 705 | :setting:`TIME_FORMAT`), this would be the format string that you want to |
| 706 | use in your language. The format is identical to the format strings used |
| 707 | by the ``now`` template tag. |
706 | 708 | |
707 | 709 | Once ``LocaleMiddleware`` determines the user's preference, it makes this |
708 | 710 | preference available as ``request.LANGUAGE_CODE`` for each |
… |
… |
|
716 | 718 | return HttpResponse("You prefer to read another language.") |
717 | 719 | |
718 | 720 | Note that, with static (middleware-less) translation, the language is in |
719 | | ``settings.LANGUAGE_CODE``, while with dynamic (middleware) translation, it's |
720 | | in ``request.LANGUAGE_CODE``. |
| 721 | :setting:`settings.LANGUAGE_CODE<LANGUAGE_CODE>`, while with dynamic |
| 722 | (middleware) translation, it's in ``request.LANGUAGE_CODE``. |
721 | 723 | |
722 | 724 | .. _settings file: ../settings/ |
723 | 725 | .. _middleware documentation: ../middleware/ |
… |
… |
|
757 | 759 | |
758 | 760 | * ``$APPPATH/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
759 | 761 | * ``$PROJECTPATH/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
760 | | * All paths listed in ``LOCALE_PATHS`` in your settings file are |
| 762 | * All paths listed in :setting:`LOCALE_PATHS` in your settings file are |
761 | 763 | searched in that order for ``<language>/LC_MESSAGES/django.(po|mo)`` |
762 | 764 | * ``$PYTHONPATH/django/conf/locale/<language>/LC_MESSAGES/django.(po|mo)`` |
763 | 765 | |
… |
… |
|
769 | 771 | to produce the binary ``django.mo`` files that are used by ``gettext``. |
770 | 772 | |
771 | 773 | 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`` |
| 774 | to make the compiler process all the directories in your :setting:`LOCALE_PATHS` |
773 | 775 | setting. |
774 | 776 | |
775 | 777 | Application message files are a bit complicated to discover -- they need the |
… |
… |
|
806 | 808 | parameter set in request. If session support is enabled, the view |
807 | 809 | saves the language choice in the user's session. Otherwise, it saves the |
808 | 810 | language choice in a cookie that is by default named ``django_language``. |
809 | | (The name can be changed through the ``LANGUAGE_COOKIE_NAME`` setting.) |
| 811 | (The name can be changed through the :setting:`LANGUAGE_COOKIE_NAME` setting.) |
810 | 812 | |
811 | 813 | After setting the language choice, Django redirects the user, following this |
812 | 814 | algorithm: |
… |
… |
|
867 | 869 | (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), |
868 | 870 | ) |
869 | 871 | |
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 |
872 | | that contains a ``locale`` directory. If you specify multiple packages, all |
873 | | those catalogs are merged into one catalog. This is useful if you have |
| 872 | Each string in ``packages`` should be in Python dotted-package syntax (the same |
| 873 | format as the strings in :setting:`INSTALLED_APPS`) and should refer to a |
| 874 | package that contains a ``locale`` directory. If you specify multiple packages, |
| 875 | all those catalogs are merged into one catalog. This is useful if you have |
874 | 876 | JavaScript that uses strings from different applications. |
875 | 877 | |
876 | 878 | You can make the view dynamic by putting the packages into the URL pattern:: |
… |
… |
|
883 | 885 | signs in the URL. This is especially useful if your pages use code from |
884 | 886 | different apps and this changes often and you don't want to pull in one big |
885 | 887 | catalog file. As a security measure, these values can only be either |
886 | | ``django.conf`` or any package from the ``INSTALLED_APPS`` setting. |
| 888 | ``django.conf`` or any package from the :setting:`INSTALLED_APPS` setting. |
887 | 889 | |
888 | 890 | Using the JavaScript translation catalog |
889 | 891 | ---------------------------------------- |
… |
… |
|
995 | 997 | * Add ``;C:\Program Files\gettext-utils\bin`` at the end of the |
996 | 998 | ``Variable value`` field |
997 | 999 | |
998 | | You may also use ``gettext`` binaries you have obtained elsewhere, so long as |
| 1000 | You may also use ``gettext`` binaries you have obtained elsewhere, so long as |
999 | 1001 | 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 |
| 1002 | have been found to not support this command. Do not attempt to use Django |
1001 | 1003 | translation utilities with a ``gettext`` package if the command ``xgettext |
1002 | 1004 | --version`` entered at a Windows command prompt causes a popup window saying |
1003 | 1005 | "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
|
|
98 | 98 | In the above example, ``{{ section.title }}`` will be replaced with the |
99 | 99 | ``title`` attribute of the ``section`` object. |
100 | 100 | |
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 ``''`` |
103 | | (the empty string) by default. |
| 101 | If you use a variable that doesn't exist, the template system will insert the |
| 102 | value of the :setting:`TEMPLATE_STRING_IF_INVALID` setting, which is set to |
| 103 | ``''`` (the empty string) by default. |
104 | 104 | |
105 | 105 | See `Using the built-in reference`_, below, for help on finding what variables |
106 | 106 | are available in a given template. |
… |
… |
|
140 | 140 | |
141 | 141 | If ``value`` isn't provided or is empty, the above will display |
142 | 142 | "``nothing``". |
143 | | |
| 143 | |
144 | 144 | :tfilter:`length` |
145 | 145 | Returns the length of the value. This works for both strings and lists; |
146 | 146 | for example:: |
… |
… |
|
148 | 148 | {{ value|length }} |
149 | 149 | |
150 | 150 | If ``value`` is ``['a', 'b', 'c', 'd']``, the output will be ``4``. |
151 | | |
| 151 | |
152 | 152 | :tfilter:`striptags` |
153 | 153 | Strips all [X]HTML tags. For example:: |
154 | 154 | |
… |
… |
|
187 | 187 | <li>{{ athlete.name }}</li> |
188 | 188 | {% endfor %} |
189 | 189 | </ul> |
190 | | |
| 190 | |
191 | 191 | :ttag:`if` and :ttag:`else` |
192 | 192 | Evaluates a variable, and if that variable is "true" the contents of the |
193 | 193 | block are displayed:: |
… |
… |
|
200 | 200 | |
201 | 201 | In the above, if ``athlete_list`` is not empty, the number of athletes |
202 | 202 | will be displayed by the ``{{ athlete_list|length }}`` variable. |
203 | | |
| 203 | |
204 | 204 | :ttag:`ifequal` and :ttag:`ifnotequal` |
205 | 205 | Display some contents if two arguments are or are not equal. For example:: |
206 | 206 | |
… |
… |
|
213 | 213 | {% ifnotequal athlete.name "Joe" %} |
214 | 214 | ... |
215 | 215 | {% endifnotequal %} |
216 | | |
| 216 | |
217 | 217 | :ttag:`block` and :ttag:`extends` |
218 | 218 | Set up `template inheritance`_ (see below), a powerful way |
219 | 219 | of cutting down on "boilerplate" in templates. |
… |
… |
|
629 | 629 | Example:: |
630 | 630 | |
631 | 631 | {% load comments i18n %} |
632 | | |
| 632 | |
633 | 633 | See :ref:`howto-custom-template-tags` for information on writing your own custom |
634 | 634 | template libraries. |
635 | 635 | |
-
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
a
|
b
|
|
258 | 258 | Note that we used ``animals``, not ``myproject.animals``. |
259 | 259 | |
260 | 260 | .. versionadded:: 1.0 |
| 261 | |
261 | 262 | You can now choose which test to run. |
262 | 263 | |
263 | 264 | If you use unit tests, as opposed to |
… |
… |
|
416 | 417 | Overview and a quick example |
417 | 418 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
418 | 419 | |
419 | | To use the test client, instantiate ``django.test.client.Client`` and retrieve |
420 | | Web pages:: |
| 420 | To use the test client, instantiate :class:`django.test.client.Client` and |
| 421 | retrieve Web pages:: |
421 | 422 | |
422 | 423 | >>> from django.test.client import Client |
423 | 424 | >>> c = Client() |
… |
… |
|
470 | 471 | Making requests |
471 | 472 | ~~~~~~~~~~~~~~~ |
472 | 473 | |
473 | | Use the ``django.test.client.Client`` class to make requests. It requires no |
474 | | arguments at time of construction: |
| 474 | Use the :class:`django.test.client.Client` class to make requests. It requires |
| 475 | no arguments at time of construction: |
475 | 476 | |
476 | 477 | .. class:: Client() |
477 | 478 | |
… |
… |
|
725 | 726 | This class provides some additional capabilities that can be useful for testing |
726 | 727 | Web sites. |
727 | 728 | |
728 | | Converting a normal ``unittest.TestCase`` to a Django ``TestCase`` is easy: |
729 | | just change the base class of your test from ``unittest.TestCase`` to |
730 | | ``django.test.TestCase``. All of the standard Python unit test functionality |
731 | | will continue to be available, but it will be augmented with some useful |
732 | | additions. |
| 729 | Converting a normal ``unittest.TestCase`` to a Django ``TestCase`` is easy: just |
| 730 | change the base class of your test from ``unittest.TestCase`` to |
| 731 | :class:`django.test.TestCase`. All of the standard Python unit test |
| 732 | functionality will continue to be available, but it will be augmented with some |
| 733 | useful additions. |
733 | 734 | |
734 | 735 | Default test client |
735 | 736 | ~~~~~~~~~~~~~~~~~~~ |
… |
… |
|
738 | 739 | |
739 | 740 | .. attribute:: TestCase.client |
740 | 741 | |
741 | | Every test case in a ``django.test.TestCase`` instance has access to an |
| 742 | Every test case in a :class:`django.test.TestCase` instance has access to an |
742 | 743 | instance of a Django test client. This client can be accessed as |
743 | 744 | ``self.client``. This client is recreated for each test, so you don't have to |
744 | 745 | worry about state (such as cookies) carrying over from one test to another. |
… |
… |
|
803 | 804 | |
804 | 805 | Once you've created a fixture and placed it somewhere in your Django project, |
805 | 806 | you can use it in your unit tests by specifying a ``fixtures`` class attribute |
806 | | on your ``django.test.TestCase`` subclass:: |
| 807 | on your :class:`django.test.TestCase` subclass:: |
807 | 808 | |
808 | 809 | from django.test import TestCase |
809 | 810 | from myapp.models import Animal |
… |
… |
|
846 | 847 | particular URL. |
847 | 848 | |
848 | 849 | In order to provide a reliable URL space for your test, |
849 | | ``django.test.TestCase`` provides the ability to customize the URLconf |
| 850 | :class:`django.test.TestCase` provides the ability to customize the URLconf |
850 | 851 | configuration for the duration of the execution of a test suite. If your |
851 | 852 | ``TestCase`` instance defines an ``urls`` attribute, the ``TestCase`` will use |
852 | | the value of that attribute as the ``ROOT_URLCONF`` for the duration of that |
853 | | test. |
| 853 | the value of that attribute as the :setting:`ROOT_URLCONF` for the duration of |
| 854 | that test. |
854 | 855 | |
855 | 856 | For example:: |
856 | 857 | |
… |
… |
|
1074 | 1075 | :synopsis: Helpers to write custom test runners. |
1075 | 1076 | |
1076 | 1077 | To assist in the creation of your own test runner, Django provides a number of |
1077 | | utility methods in the ``django.test.utils`` module. |
| 1078 | utility methods in the :mod:`django.test.utils` module. |
1078 | 1079 | |
1079 | 1080 | .. function:: setup_test_environment() |
1080 | 1081 | |
… |
… |
|
1109 | 1110 | Returns the name of the test database that it created. |
1110 | 1111 | |
1111 | 1112 | ``create_test_db()`` has the side effect of modifying |
1112 | | ``settings.DATABASE_NAME`` to match the name of the test database. |
| 1113 | :setting:`settings.DATABASE_NAME<DATABASE_NAME>` to match the name of the |
| 1114 | test database. |
1113 | 1115 | |
1114 | 1116 | .. versionchanged:: 1.0 |
| 1117 | |
1115 | 1118 | ``create_test_db()`` now returns the name of the test database. |
1116 | 1119 | |
1117 | 1120 | .. function:: destroy_test_db(old_database_name, verbosity=1) |