Opened 17 years ago

Closed 17 years ago

#6253 closed (wontfix)

reverse() in tutorial part 4 should use the function itself rather than the string representation

Reported by: alberto@… Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the vote() function example, at the tutorial part 4 (http://www.djangoproject.com/documentation/tutorial04/), it's better to use

def vote(request, poll_id):
  ...
  return HttpResponseRedirect(reverse(results, args=(p.id,)))

rather then

def vote(request, poll_id):
  ...
  return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,)))

to decouple the polls app from the mysite project.

Change History (3)

comment:1 by Chris Beaven, 17 years ago

Summary: Decouple app from project in vote() function example - tutorial part 4reverse() in tutorial part 4 should use the function itself rather than the string representation
Triage Stage: UnreviewedDesign decision needed

There are more places than this needed to fix to decouple the app.

That said, this specific change isn't a bad idea, is it?

comment:2 by James Bennett, 17 years ago

Probably the most reliable thing is to use a named pattern; that would get people into the habit of naming their patterns which, in turn, reduces the potential for problems from multiple URLs using the same view function.

comment:3 by Malcolm Tredinnick, 17 years ago

Resolution: wontfix
Status: newclosed

This change would be a bad idea. Using reverse() against function objects is very fragile. The problem is that they are automatically imported under different paths and it is officially Very Hard(tm) in Python to tell when they are the same object (short of md5-summing the code objects, which seems like overkill). And, really, I don't care very much that that's case, since using named URL patterns is safer and saner on a number of levels.

Eventually, there's a bit of a sanity pass needed over the code samples in the tutorial to bring them all into alignment and using URL patterns (after introducing them earlier) is probably the best idea. However, the change suggested here, although well intentioned actually leads to subtle trouble.

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