diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2012-10-07 20:11:12 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2012-10-07 20:21:07 -0300 |
| commit | ec1aad1671bfbba7ef58e7477dd14d7add065838 (patch) | |
| tree | 9b3ae0431e0da2d4450d8b669f69bdc7e3c37c9d /docs/ref/models | |
| parent | 34a736b7521def321b2104d541e634134c5d1c62 (diff) | |
Added section about URL reversion to URL mapper document.
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/instances.txt | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 92fc4ef31a..1ba41148b0 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -494,12 +494,16 @@ defined. If it makes sense for your model's instances to each have a unique URL, you should define ``get_absolute_url()``. It's good practice to use ``get_absolute_url()`` in templates, instead of -hard-coding your objects' URLs. For example, this template code is bad:: +hard-coding your objects' URLs. For example, this template code is bad: + +.. code-block:: html+django <!-- BAD template code. Avoid! --> <a href="/people/{{ object.id }}/">{{ object.name }}</a> -This template code is much better:: +This template code is much better: + +.. code-block:: html+django <a href="{{ object.get_absolute_url }}">{{ object.name }}</a> @@ -535,7 +539,9 @@ pattern name) and a list of position or keyword arguments and uses the URLconf patterns to construct the correct, full URL. It returns a string for the correct URL, with all parameters substituted in the correct positions. -The ``permalink`` decorator is a Python-level equivalent to the :ttag:`url` template tag and a high-level wrapper for the :func:`django.core.urlresolvers.reverse()` function. +The ``permalink`` decorator is a Python-level equivalent to the :ttag:`url` +template tag and a high-level wrapper for the +:func:`django.core.urlresolvers.reverse()` function. An example should make it clear how to use ``permalink()``. Suppose your URLconf contains a line such as:: |
