3

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.

iJK
  • 4,655
  • 12
  • 63
  • 95

2 Answers2

4

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/
dting
  • 38,604
  • 10
  • 95
  • 114
  • 2
    Nice find. "if pk is found, this method performs a primary-key based lookup using that value. If no pk argument is found, it looks for a slug argument, and performs a slug lookup using the SingleObjectMixin.slug_field." – Yuji 'Tomita' Tomita Apr 26 '11 at 02:17
  • Thanks for the help guys. If i remove the pk look up from the url and add the value "id" to slug_field then I get the same error again. Am I doing this wrong? – iJK Apr 26 '11 at 02:35
  • You'd need to set `slug_field` to "id" and accept an argument called "slug". (?P...) – Yuji 'Tomita' Tomita Apr 26 '11 at 04:08
0

I did the below change, and it worked.

Upgrade the debug toolbar to 1.5 or downgrade sqlparse to 0.1.x.

Source : https://github.com/jazzband/django-debug-toolbar/issues/862 (Big thanks to the user aaugustin from github)

SuperNova
  • 25,512
  • 7
  • 93
  • 64