Opened 14 years ago

Closed 14 years ago

#15138 closed (fixed)

Error in documentation simple_tag decorator.

Reported by: elbarto Owned by: elbarto
Component: Documentation Version:
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

In http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#shortcut-for-simple-tags :

The new examples, that use takes_context argument, have a second argument (format_string) which are never used.

# The first argument *must* be called "context" here.
def current_time(context, format_string):
    timezone = context['timezone']
    return your_get_current_time_method(timezone)

register.simple_tag(takes_context=True)(current_time)
@register.simple_tag(takes_context=True)
def current_time(context, format_string):
    timezone = context['timezone']
    return your_get_current_time_method(timezone)

I fixed it with a patch.

Attachments (2)

inclusion_tag_doc.diff (816 bytes ) - added by elbarto 14 years ago.
simple_tag_doc.diff (967 bytes ) - added by elbarto 14 years ago.
Included the arguments in the fictitious your_get_current_time_method().

Download all attachments as: .zip

Change History (4)

by elbarto, 14 years ago

Attachment: inclusion_tag_doc.diff added

comment:1 by Russell Keith-Magee, 14 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Accepted that the example is at least slightly ambiguous; however, the ambiguity should be fixed by using the argument, not by removing it. The point of the example is to demonstrate that "context" must be the first argument, not to say that you can't have other arguments.

by elbarto, 14 years ago

Attachment: simple_tag_doc.diff added

Included the arguments in the fictitious your_get_current_time_method().

comment:2 by Gabriel Hurley, 14 years ago

Resolution: fixed
Status: newclosed

In [15448]:

Fixed #15138 -- Clarified a slightly ambiguous example in the custom template tag docs. Thanks to elbarto for the report and patch.

Note: See TracTickets for help on using tickets.
Back to Top