vidit
vidit

Reputation: 957

Replacing object_list with ListView: AttributeError

I am trying to update a Django application to v1.6. When I replace the deprecated

return object_list(request,  template_name='generic_list.html', *args, **kwargs)

with

return ListView.as_view(template_name='generic_list.html', *args, **kwargs)

I get this error:

AttributeError at /assets/asset/list/
'function' object has no attribute 'status_code'
Request Method: GET
Request URL:    `http://127.0.0.1:8000/assets/asset/list/`
Django Version: 1.6
Exception Type: AttributeError
Exception Value:    
'function' object has no attribute 'status_code'
Exception Location: c:\Program Files (x86)\Python\lib\site-packages\django\middleware\locale.py in process_response, line 41

What am I doing wrong?

Upvotes: 1

Views: 1259

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

You don't say so, but you seem to be using the generic views at the end of an existing view. You wouldn't normally do that with a class-based generic view: the whole point of them being classes is that you can extend them by subclassing, adding your own functionality that way.

However, you can probably fix your immediate error in the short term by actually calling the view: what you are doing here is simply creating the view object (which itself is a callable). You still need to call that object, passing it the request and any params:

view = ListView.as_view(template_name='generic_list.html')
return view(request, *args, **kwargs)

But as I say I do not recommend doing that: you should subclass ListView and extend it.

Upvotes: 2

Related Questions