summaryrefslogtreecommitdiff
path: root/docs/templates_python.txt
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-09-15 21:21:37 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-09-15 21:21:37 +0000
commitfb6a0c8ffa1cd74c63aaf4b011665e5952d449e7 (patch)
tree4af2f7d6a2d1d91adf80243c67176effecf0c8b8 /docs/templates_python.txt
parentc8f6e485b8b7329418ca030421b9bde4ec164854 (diff)
queryset-refactor: Merged to [6155]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6332 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/templates_python.txt')
-rw-r--r--docs/templates_python.txt32
1 files changed, 19 insertions, 13 deletions
diff --git a/docs/templates_python.txt b/docs/templates_python.txt
index 261eaedf74..150aa70fdf 100644
--- a/docs/templates_python.txt
+++ b/docs/templates_python.txt
@@ -642,7 +642,23 @@ your function. Example::
"Converts a string into all lowercase"
return value.lower()
-When you've written your filter definition, you need to register it with
+Template filters which expect strings
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you're writing a template filter which only expects a string as the first
+argument, you should use the included decorator ``stringfilter``. This will
+convert an object to it's string value before being passed to your function::
+
+ from django.template.defaultfilters import stringfilter
+
+ @stringfilter
+ def lower(value):
+ return value.lower()
+
+Registering a custom filters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Once you've written your filter definition, you need to register it with
your ``Library`` instance, to make it available to Django's template language::
register.filter('cut', cut)
@@ -658,28 +674,18 @@ If you're using Python 2.4 or above, you can use ``register.filter()`` as a
decorator instead::
@register.filter(name='cut')
+ @stringfilter
def cut(value, arg):
return value.replace(arg, '')
@register.filter
+ @stringfilter
def lower(value):
return value.lower()
If you leave off the ``name`` argument, as in the second example above, Django
will use the function's name as the filter name.
-Template filters which expect strings
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If you are writing a template filter which only expects a string as the first
-argument, you should use the included decorator ``stringfilter`` which will convert
-an object to it's string value before being passed to your function::
-
- from django.template.defaultfilters import stringfilter
-
- @stringfilter
- def lower(value):
- return value.lower()
-
Writing custom template tags
----------------------------