Opened 4 years ago

Closed 4 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: UI/UX:

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 4 years ago.
simple_tag_doc.diff (967 bytes) - added by elbarto 4 years ago.
Included the arguments in the fictitious your_get_current_time_method().

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by elbarto

comment:1 Changed 4 years ago by russellm

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

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.

Changed 4 years ago by elbarto

Included the arguments in the fictitious your_get_current_time_method().

comment:2 Changed 4 years ago by gabrielhurley

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

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