Opened 12 years ago

Closed 12 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: master
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


In the vote() function example, at the tutorial part 4 (, it's better to use

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

rather then

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

to decouple the polls app from the mysite project.

Change History (3)

comment:1 Changed 12 years ago by Chris Beaven

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 Changed 12 years ago by James Bennett

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 Changed 12 years ago by Malcolm Tredinnick

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