Opened 15 years ago

Closed 15 years ago

#12971 closed (invalid)

Generic View Tutorial contains broken / incorrect syntax

Reported by: quietlyconfident <dykema@…> Owned by: nobody
Component: Documentation Version: 1.1
Severity: Keywords: generic view tutorial
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The tutorial part 4 here: http://docs.djangoproject.com/en/dev/intro/tutorial04/#use-generic-views-less-code-is-better contains the following example (edited for brevity):

urlpatterns = patterns('',
    (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
    ...
  )

Of note, the 2nd argument, django.views.generic.... , is quoted as if it were a string. It's not and quoting it as such causes an error at runtime. I'm not precisely sure how to submit a patch for documentation, but for all four of those examples, the 2nd argument shouldn't be quoted, it should look like this:

urlpatterns = patterns('',
    (r'^$', django.views.generic.list_detail.object_list, info_dict),
    ...
  )

And it would be even better IMHO if some of the fluff were taken out of that module name, by importing object_list and object detail from the proper module:

...

from django.views.generic.list_detail import object_list, object_detail

urlpatterns = patterns('',
    (r'^$', object_list, info_dict),
    ...
  )

This last one seems to be the most readable.

Change History (1)

comment:1 by Karen Tracey, 15 years ago

Resolution: invalid
Status: newclosed

You don't mention specifics of the "error at runtime" you see so I'm not sure what's gone wrong in your setup. Strings for the 2nd tuple item in a url pattern are valid, and consistent with how url patterns are specified throughout the tutorial. Callables are also allowed (see http://docs.djangoproject.com/en/dev/topics/http/urls/#passing-callable-objects-instead-of-strings) but not required.

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