Skip to content

Commit

Permalink
Edited docs/templates_python.txt change from [6143]
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6159 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Sep 14, 2007
1 parent 2bec822 commit e86d358
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/templates_python.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -642,19 +642,23 @@ your function. Example::
"Converts a string into all lowercase" "Converts a string into all lowercase"
return value.lower() return value.lower()


Template filters which expect strings Template filters that expect strings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


If you're writing a template filter which only expects a string as the first If you're writing a template filter that only expects a string as the first
argument, you should use the included decorator ``stringfilter``. This will argument, you should use the decorator ``stringfilter``. This will
convert an object to it's string value before being passed to your function:: convert an object to its string value before being passed to your function::


from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter


@stringfilter @stringfilter
def lower(value): def lower(value):
return value.lower() return value.lower()


This way, you'll be able to pass, say, an integer to this filter, and it
won't cause an ``AttributeError`` (because integers don't have ``lower()``
methods).

Registering a custom filters Registering a custom filters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Expand Down

0 comments on commit e86d358

Please sign in to comment.