title: NoReverseMatch django class based
body: <p>edit.</p>
  
  <p>sorry I'm having a hard time and thanks for your help how do I do that? </p>
  
  <p>model</p>
  
  <pre><code>   created_by = models.ForeignKey(User) 
  
  
  
     def get_absolute_url(self):
          return reverse('author_update', kwargs={'pk': self.pk, 'user_id': self.created_by})
  </code></pre>
  
  <p>Could be related to the error <a href="https://stackoverflow.com/questions/21440891/type-error-with-django-class-based-view">Type error with django class based view</a></p>
  
  <p>I get this error </p>
  
  <pre><code>NoReverseMatch at /author/add/4
  Reverse for 'author_add' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['author/add/(?P&lt;user_id&gt;\\d+)$']
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code> url(r'^author/add/(?P&lt;user_id&gt;\d+)$', AuthorCreate.as_view(), name='author_add'),
   url(r'^author/(?P&lt;user_id&gt;\d+)/(?P&lt;pk&gt;\d+)$', AuthorUpdate.as_view(), name='author_update'),
   url(r'^author/(?P&lt;user_id&gt;\d+)/(?P&lt;pk&gt;\d+)/delete/$', AuthorDelete.as_view(), name='author_delete'),
   url(r'^author/list/(?P&lt;user_id&gt;\d+)$', AuthorList.as_view(), name='author_list'),
  </code></pre>
  
  <p>views.py for createview</p>
  
  <pre><code>class AuthorCreate(LoginRequiredMixin, CreateView):
      model = Author
      fields = [ 'firstName', 'lastName', ]
      template_name = 'authorCreate.html'
      success_url = reverse_lazy('author_list')
  
      def form_valid(self, form):
          form.instance.created_by = self.request.user
          return super(AuthorCreate, self).form_valid(form)
  
      def get_context_data(self, **kwargs):
          context = super(AuthorCreate, self).get_context_data(**kwargs)
          if int(self.kwargs['user_id']) != self.request.user.id:
              raise PermissionDenied
          return context
  </code></pre>
  
  <p>views.py for listview</p>
  
  <pre><code>class AuthorList(LoginRequiredMixin, ListView):
      template_name = 'authorList.html'
      queryset = Author.objects.all()
  
      def get_context_data(self, **kwargs):
          context = super(AuthorList, self).get_context_data(**kwargs)
          if int(self.kwargs['user_id']) != self.request.user.id:
              raise PermissionDenied
          return context
  </code></pre>
  
  <p>authorCreate.html</p>
  
  <pre><code>&lt;form method="post"&gt;{% csrf_token %}
      {{ form.as_p }}
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>authorList.html</p>
  
  <pre><code>   {{ request.user.username}} 
  
      &lt;ul&gt;
          {% for author in object_list %}
              &lt;li&gt;{{ author.firstName }}
                   &lt;a href="{% url "author_update" author.id %}"&gt;{{ author.firstName }}&lt;/a&gt;
                   &lt;a href="{% url "author_delete" author.id %}"&gt;delete&lt;/a&gt;
              &lt;/li&gt;
           {% endfor %}
      &lt;/ul&gt;
  </code></pre>
  
  <p>terminal error</p>
  
  <pre><code>Internal Server Error: /author/add/4
  Traceback (most recent call last):
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view
      return self.dispatch(request, *args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/utils/decorators.py", line 29, in _wrapper
      return bound_func(*args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
      return view_func(request, *args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in bound_func
      return func(self, *args2, **kwargs2)
    File "/home/ronald/best/A2/0124/vort/larb/views.py", line 52, in dispatch
      return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch
      return handler(request, *args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 205, in post
      return super(BaseCreateView, self).post(request, *args, **kwargs)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 171, in post
      return self.form_valid(form)
    File "/home/ronald/best/A2/0124/vort/larb/views.py", line 82, in form_valid
      return super(AuthorCreate, self).form_valid(form)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 148, in form_valid
      return super(ModelFormMixin, self).form_valid(form)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 78, in form_valid
      return HttpResponseRedirect(self.get_success_url())
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 132, in get_success_url
      if self.success_url:
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/utils/functional.py", line 125, in __wrapper__
      res = func(*self.__args, **self.__kw)
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 509, in reverse
      return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
    File "/home/ronald/best/A2/0124/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 429, in _reverse_with_prefix
      (lookup_view_s, args, kwargs, len(patterns), patterns))
  NoReverseMatch: Reverse for 'author_add' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['author/add/(?P&lt;user_id&gt;\\d+)$']
  </code></pre>