I am trying to use DetailView generic class in my test app and this is what I have in my view
*updated model * from this example
class AuthorDetailView(DetailView):
context_object_name = "author"
queryset = Author.objects.all()
slug_field = "id"
def get_object(self):
object = super(AuthorDetailView, self).get_object()
return object
as a test
and in my urls.py file I got
('^author/(\d+)/$', Author.AuthorDetailView.as_view()),
when I navigate to http://localhost:8000/author/1 I get the following error
Typer Error get() takes exactly 2 arguments (3 given)
Traceback:
File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.6/site-packages/django/views/generic/base.py" in view
47. return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.6/site-packages/django/views/generic/base.py" in dispatch
68. return handler(request, *args, **kwargs)
Exception Type: TypeError at /author/1/
Exception Value: get() takes exactly 2 arguments (3 given)
I don't really understand what is going on in base.py.
Try this urlconf
from books.views import AuthorDetailView
urlpatterns = patterns('',
#...
(r'^authors/(?P<pk>\d+)/$', AuthorDetailView.as_view()),
)
and navigate to:
http://localhost:8000/author/1/