Mirage
Mirage

Reputation: 31548

Getting django error in the view with custom function

I am using django class based view

class MyView(TemplateView):
    def return_JSON(self, object_id):
        parent = models.UserForm.objects.get(pk=object_id)

url(r'^return/(?P<object_id>\d+)/json/', views.MyView().return_JSON, name="return_json")

I get this error

return_JSON() got multiple values for keyword argument 'object_id'

Upvotes: 0

Views: 153

Answers (1)

You're doing something very odd here.

You're using CBVs, but passing a function as the view function. Remember, the normal signature for CBVs is to pass in MyCBV.as_view(). No CBV machinery runs without running it through as_view() or dispatch().

But if you insist, you just need to add a new argument to your function...

def return_JSON(self, request, object_id):
    #                 ^^^^^^^ this
    return http.HttpResponse("Foo!")

Upvotes: 3

Related Questions