title: Django AssertionError at url
body: <p>While learning Django rest framework, I got a <strong>AssertionError at /tasks/1</strong> error </p>
  
  <p><strong>Expected view TaskDetail to be called with a URL keyword argument named "pk". Fix your URL conf, or set the <code>.lookup_field</code> attribute on the view correctly.</strong></p>
  
  <p>My model.py</p>
  
  <pre><code>class Task(models.Model):
      owner=models.ForeignKey('auth.User',related_name='tasks')
      completed=models.BooleanField(default=False)
      title=models.CharField(max_length=100)
      description=models.TextField()
  </code></pre>
  
  <p>serializer.py</p>
  
  <pre><code>class TaskSerializer(serializers.ModelSerializer):
  
  class Meta:
      model = Task
      read_only=('owner.username',)
      fields=('title','description','completed','owner.username')
  </code></pre>
  
  <p>permission.py</p>
  
  <pre><code>class IsOwnerOrReadOnly(BasePermission):
      def has_object_permission(self, request, view, obj):
          if request.method is SAFE_METHODS:
              return True
  
          return obj.owner==request.user
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class TasksMixins(object):
      queryset = Task.objects.all()
      serializer_class=TaskSerializer
      permission_classes=(IsOwnerOrReadOnly,)
  
      def pre_save(self,obj):
          obj.owner=self.request.user
  
  class TaskList(TasksMixins,ListCreateAPIView):
      pass
  
  class TaskDetail(TasksMixins,RetrieveUpdateDestroyAPIView):
      pass
  </code></pre>
  
  <p>Urls.py</p>
  
  <pre><code>urlpatterns = [
      url(r'^$', views.home, name='home'),
      url(r'^tasks/$', views.TaskList.as_view(), name='task_list'),
      url(r'^tasks/(?P&lt;id&gt;[0-9]+)$', views.TaskDetail.as_view(), name='task_detail')
  ]
  </code></pre>
  
  <p>Traceback</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
      response = self.process_exception_by_middleware(e, request)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
      return view_func(*args, **kwargs)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
      return self.dispatch(request, *args, **kwargs)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/rest_framework/views.py", line 466, in dispatch
      response = self.handle_exception(exc)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/rest_framework/views.py", line 463, in dispatch
      response = handler(request, *args, **kwargs)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/rest_framework/generics.py", line 286, in get
      return self.retrieve(request, *args, **kwargs)
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/rest_framework/mixins.py", line 56, in retrieve
      instance = self.get_object()
    File "/home/amogh/PycharmProjects/env_1.9/local/lib/python2.7/site-packages/rest_framework/generics.py", line 93, in get_object
      (self.__class__.__name__, lookup_url_kwarg)
  AssertionError: Expected view TaskDetail to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
  </code></pre>
  
  <p>When ever I navigate to the link I get this error</p>
  
  <p>Any help is much appreciated...Thanks in advace</p>
  
  <p><a href="http://i.stack.imgur.com/QO4Qt.png" rel="nofollow">error image</a></p>