Error when updating function-based views to class-based views in Django Rest Framework
<p>I've been in the process of running through the tutorials on Django Rest Framework to build a simple todo list app. </p>

<p>When I transitioned from a function-based view to a class-based view, I started getting a stack trace to Django and all http calls started failing.</p>

<p>I'm using <code>virtualenv</code> to isolate dependencies, and using Python 3.5.2.</p>

<p>Anyone have any ideas about what's going on, or how to resolve this error?</p>

<p>I'm chalking this up to a configuration error or a version mismatch, but I'm not sure where to start.</p>

<p>/views.py:</p>

<pre><code>from django.http import Http404
from list.models import List
from list.serializers import ListSerializer
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status

class ListsView(APIView):
        """
        List all lists.
        """
        def get(self, request, format=None):
                lists = List.objects.all()
                serializer = ListSerializer(lists, many=True)
                return Response(serializer.data)

        ...
</code></pre>

<p>/urls.py</p>

<pre><code>from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from list import views

urlpatterns = [
    url(r'^lists/$', views.ListsView),
    url(r'^lists/(?P&lt;pk&gt;[0-9]+)/$', views.ListView),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/$', views.ListItemsView),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/(?P&lt;pk&gt;[0-9]+)/$', views.ListItemView),
]

urlpatterns = format_suffix_patterns(urlpatterns)
</code></pre>

<p>Input:</p>

<pre><code>curl http://localhost:8000/lists/
</code></pre>

<p>Trace:</p>

<pre><code>Internal Server Error: /lists/
Traceback (most recent call last):
  File "&lt;pwd&gt;/env/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "&lt;pwd&gt;/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "&lt;pwd&gt;/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "&lt;pwd&gt;/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
[29/Aug/2016 00:03:32] "GET /lists/ HTTP/1.1" 500 61615
</code></pre>

<p>Env:</p>

<pre><code>python 3.5.2
</code></pre>

<p>Requirements:</p>

<pre><code>Django==1.10
django-lint==2.0.4
djangorestframework==3.4.6
logilab-astng==0.24.3
logilab-common==1.2.2
psycopg2==2.6.2
Pygments==2.1.3
pylint==0.28.0
six==1.10.0
</code></pre>

<p>@SergeyGornostaev had the right intuition to look at and post <code>urls.py</code>.</p>

<p>In the refactor from function-based views to class-based views, I neglected to call <code>as_view()</code> on the views when I updated the routing.</p>

<p>Before: <code>url(&lt;pattern&gt;, views.ListsView)</code></p>

<p>After: <code>url(&lt;pattern&gt;, views.ListView.as_view())</code></p>

<p>This resolved the error.</p>

<hr>

<p>Full /urls.py before:</p>

<pre><code>from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from list import views

urlpatterns = [
    url(r'^lists/$', views.ListsView),
    url(r'^lists/(?P&lt;pk&gt;[0-9]+)/$', views.ListView),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/$', views.ListItemsView),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/(?P&lt;pk&gt;[0-9]+)/$', views.ListItemView),
]

urlpatterns = format_suffix_patterns(urlpatterns)
</code></pre>

<p>Full /urls.py after:</p>

<pre><code>from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from list import views

urlpatterns = [
    url(r'^lists/$', views.ListsView.as_view()),
    url(r'^lists/(?P&lt;pk&gt;[0-9]+)/$', views.ListView.as_view()),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/$', views.ListItemsView.as_view()),
    url(r'^lists/(?P&lt;list&gt;[0-9]+)/items/(?P&lt;pk&gt;[0-9]+)/$', views.ListItemView.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)
</code></pre>

python django django-rest-framework python-3.5