开发者

Django get() takes exactly 2 arguments (3 given)

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/


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜