0

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'
2

1 Answer 1

3

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!")
Sign up to request clarification or add additional context in comments.

2 Comments

i tried that and i get this error object has no attribute 'request'
That makes no sense. There is nothing referencing a request attribute anywhere in this code. Post your traceback. Also, for future reference, you're missing KEY information. which object has no attribute request? If you want to spit out a half line of debug information, include the important parts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.