View not found for views with number at the end
<p>I'm trying to do a <code>reverse</code> like this:</p>

<pre><code>print reverse("shows-view")
</code></pre>

<p>This is in my <code>urls.py</code>:</p>

<pre><code>url(r'^shows/(\d+)$', views.show_details, name="shows-view"),
</code></pre>

<p>Whenever I try to do that, it just returns:</p>

<pre><code>Reverse for 'shows-view' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['shows/(\\d+)$']
</code></pre>

<p>But if I try to access the page directly (<code>http://localhost/shows/3333</code>) then it works fine</p>

<p>But if I do a reverse for other views like this:</p>

<pre><code>print reverse("shows-default-view")
</code></pre>

<p>with the following declaration in the same <code>urls.py</code> file:</p>

<pre><code>url(r'^shows/', views.popular, name="shows-default-view"),
</code></pre>

<p>then it works fine. Does anyone have any idea why?</p>

<p>The URL in question accepts an argument <code>(\d+)</code> which you are not passing your <code>reverse</code> function. Just think: this is a details view, but <em>which</em> show do you want to display?</p>

<p>To fix, call <code>reverse</code> with the <code>args</code> parameter:</p>

<pre><code>reverse("shows-default-view", args=[1]) # to show show with id of 1
</code></pre>

<p>In general for URL's like that, the recommendation is to have a named captured group:</p>

<pre><code>url(r'^shows/(?P&lt;pk&gt;\d+)$', views.show_details, name="shows-view")
</code></pre>

<p>And then the call to <code>reverse</code> will be:</p>

<pre><code>reverse("shows-default-view", kwargs={'pk': 1})
</code></pre>

<p>To use <code>reverse</code> in a template, just put the two arguments together:</p>

<pre><code>{% url 'shows-view' 1 %}
</code></pre>

python django python-2.7 django-templates django-views