Reverse for 'detail' with arguments '()' and keyword arguments '{'pk': 2}' not found. 1 pattern(s) tried: ['music/(?P<album_id>[0-9]+)/$']
<p>My traceback:</p>

<pre><code>File "D:\virtualEnv\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "D:\virtualEnv\lib\site-packages\django\views\generic\base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "D:\virtualEnv\lib\site-packages\django\views\generic\base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "D:\virtualEnv\lib\site-packages\django\views\generic\edit.py" in post
  217.         return super(BaseCreateView, self).post(request, *args, **kwargs)

File "D:\virtualEnv\lib\site-packages\django\views\generic\edit.py" in post
  183.             return self.form_valid(form)

File "D:\virtualEnv\lib\site-packages\django\views\generic\edit.py" in form_valid
  163.         return super(ModelFormMixin, self).form_valid(form)

File "D:\virtualEnv\lib\site-packages\django\views\generic\edit.py" in form_valid
  79.         return HttpResponseRedirect(self.get_success_url())

File "D:\virtualEnv\lib\site-packages\django\views\generic\edit.py" in get_success_url
  151.                 url = self.object.get_absolute_url()

File "D:\virtualEnv\website\music\models.py" in get_absolute_url
  13.         return reverse('music:detail', kwargs={'pk': self.pk})

File "D:\virtualEnv\lib\site-packages\django\urls\base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\virtualEnv\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  389.             (lookup_view_s, args, kwargs, len(patterns), patterns)

Exception Type: NoReverseMatch at /music/album/add/
Exception Value: Reverse for 'detail' with arguments '()' and keyword arguments '{'pk': 2}' not found. 1 pattern(s) tried: ['music/(?P&lt;album_id&gt;[0-9]+)/$']
</code></pre>

<p>my Album model is:</p>

<pre><code>class Album(models.Model):
    artist = models.CharField(max_length=250)
    album_title = models.CharField(max_length=500)
    genre = models.CharField(max_length=100)
    album_logo = models.CharField(max_length=1000)

    def get_absolute_url(self):
        return reverse('music:detail', kwargs={'pk': self.pk})
</code></pre>

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

<pre><code>class IndexView(generic.ListView):
    template_name = 'music/index.html'
    context_object_name = 'all_albums'

    def get_queryset(self):
        return Album.objects.all()

class DetailView(generic.DetailView):
    model = Album
    template_name = 'music/detail.html'

class AlbumCreate(CreateView):
    model = Album
    fields = ['artist', 'album_title','genre', 'album_logo']
</code></pre>

<p>urls:</p>

<pre><code>app_name = 'music'    
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P&lt;album_id&gt;[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'album/add/$', views.AlbumCreate.as_view(), name='album-add'),
    ]
</code></pre>

<p>Why this code not work properly in D:\virtualEnv\website\music\models.py in get_absolute_url:</p>

<pre><code>        return reverse('music:detail', kwargs={'pk': self.pk}) 
</code></pre>

<p>When I tried to add album using form it gave above errors. How do I fix this issues?</p>

<p><strong>Edit:</strong></p>

<p>When I changed album_id with pk, it gives following errors:</p>

<pre><code>Template error:
In template D:\virtualEnv\website\music\templates\music\detail.html, error at line 14
   Reverse for 'favorite' with arguments '(4,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []   4 : 
   5 : &lt;img src="{{album.album_logo}}" &gt;
   6 : 
   7 : &lt;h1&gt;{{album.album_title }}&lt;/h1&gt;
   8 : &lt;h3&gt;{{album.artist}}&lt;/h3&gt;
   9 : 
   10 : {% if error_message %}
   11 :     &lt;p&gt;&lt;strong&gt;{{ error_message }}&lt;/strong&gt;&lt;/p&gt;
   12 : {% endif %}
   13 : 
   14 : &lt;form action=" {% url 'music:favorite' album.id %} " method="post"&gt;
   15 :     {% csrf_token %}
   16 :     {% for song in album.song_set.all %}
   17 :     &lt;input type="radio" id="song{{ forloop.counter}}" name="song" value="{{song.id}}"&gt;
   18 :     &lt;label for= "song{{ forloop.counter}}"&gt;
   19 :         {{song.song_title}}
   20 :         {% if song.is_favorite %}
   21 :             &lt;img src="http://i.imgur.com/b9b13Rd.png"/&gt;
   22 :         {% endif %}
   23 :     &lt;/label&gt;&lt;br&gt;
   24 :     {% endfor %}


Traceback:

File "D:\virtualEnv\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "D:\virtualEnv\lib\site-packages\django\core\handlers\base.py" in _get_response
  215.                 response = response.render()

File "D:\virtualEnv\lib\site-packages\django\template\response.py" in render
  109.             self.content = self.rendered_content

File "D:\virtualEnv\lib\site-packages\django\template\response.py" in rendered_content
  86.         content = template.render(context, self._request)

File "D:\virtualEnv\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "D:\virtualEnv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "D:\virtualEnv\lib\site-packages\django\template\defaulttags.py" in render
  447.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "D:\virtualEnv\lib\site-packages\django\urls\base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "D:\virtualEnv\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  389.             (lookup_view_s, args, kwargs, len(patterns), patterns)

Exception Type: NoReverseMatch at /music/4/
Exception Value: Reverse for 'favorite' with arguments '(4,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
</code></pre>

<p>Your <code>get_absolute_url</code> method passes a <code>kwarg</code> called <code>pk</code>, but your URL pattern expects an argument called <code>album_id</code>. </p>

python django