Code

Opened 7 years ago

Closed 7 years ago

#4149 closed (invalid)

cache_page decorator documented incorrectly

Reported by: SmileyChris Owned by: jacob
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

While investigating #2564, I found that the problem was actually incorrect use of the cache_page decorator, but the documentation recommends this incorrect format.

The current documentation says

It’s easy to use:

from django.views.decorators.cache import cache_page

def slashdot_this(request):
    ...

slashdot_this = cache_page(slashdot_this, 60 * 15)

Or, using Python 2.4’s decorator syntax:

@cache_page(60 * 15)
def slashdot_this(request):
    ...

The Python 2.4 syntax can not be used in this case.

@cache_page(60 * 15) is actually equivalent slashdot_this = cache_page(60 * 15)(slashdot_this) which is obviously incorrect (the cache_page decorator expects the both the function and any arguments to be passed directly to it)

The decorator (which is actually from django.utils.decorators.decorator_from_middleware) is the problem here and perhaps it's format should change - but for now, let's just fix the documentation.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

This is a problem with the decorator, not the documentation.

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.