Code

Opened 7 years ago

Closed 7 years ago

#4793 closed (fixed)

template documentation has wrong example

Reported by: Can Burak Cilingir <canburak@…> Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

following code causes "module has no stringfilter" error

from django import template

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

you also need to register that filter (stringfilter is not registering it). correct example would be:

from django import template

@register.filter(name="endswith")
@template.defaultfilters.stringfilter
def endswith(value,arg):
    return value.endswith(arg)

Attachments (1)

4793.patch (2.0 KB) - added by SmileyChris 7 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Example is here: http://www.djangoproject.com/documentation/templates_python/#template-filters-which-expect-strings

The example just shows the code which needs to be added for the specific case, not a full working example of a template.

...although perhaps the "registering a filter" bit could have a heading of it's own and it could go below "template filters which expect strings" to clarify things.

Changed 7 years ago by SmileyChris

comment:2 Changed 7 years ago by SmileyChris

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin

comment:3 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [6143]) Fixed #4793 -- Tweaked custom filter documentation a little to possibly reduce some confusion. Thanks, SmileyChris.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.