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'
Alasdair
  • 298,606
  • 55
  • 578
  • 516
Mirage
  • 30,868
  • 62
  • 166
  • 261
  • 1
    go through http://stackoverflow.com/questions/13544504/django-form-got-multiple-values-for-keyword-argument & http://stackoverflow.com/questions/3387766/object-detail-got-multiple-values-for-keyword-argument-queryset-while-inputt – avasal Dec 07 '12 at 05:47
  • i tried putting request in the function then i get `object has no attribute 'request'` – Mirage Dec 07 '12 at 05:59

1 Answers1

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!")
Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
  • i tried that and i get this error `object has no attribute 'request'` – Mirage Dec 07 '12 at 08:59
  • 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. – Yuji 'Tomita' Tomita Dec 07 '12 at 09:05