[Answered ]-Django generic DetailView

2👍

The problem is in the url pattern. The DetailView needs the primary key to find the right object to display, but the pattern r'^view/([0-9]+)/$' does not specify that the matching number should be used as the primary key. Try r'^view/(?P<pk>[0-9]+)/$' (pk stands for primary key).

Also see the example at DetailView doocs (which provides slug instead of pk). Custom get_context_data should not be neede for pk and slug.

Leave a comment