Url argument with Django
<p>I'm having some problem with my url in Django (1.9)</p>

<p>Tried many way to solve it, but still the same type of error</p>

<pre><code>Reverse for 'elus' with arguments '()' and keyword arguments '{u'council': u'CFVU'}' not found. 1 pattern(s) tried: ['elus/(?P&lt;council&gt;[A-B]+)$']
</code></pre>

<p>The actual code is this : </p>

<p>View : </p>

<pre><code>class RepresentativeView(ListView):
    model = Representative
    template_name= 'lea/elus.html'
    context_object_name = 'represents'

    def get_queryset(self, council):

        return Representative.objects.filter(active=True).filter(council=council).order_by(order)
</code></pre>

<p>url : </p>

<pre><code>url(r'^elus/(?P&lt;council&gt;[A-B]+)$', views.RepresentativeView.as_view(), name='elus'),
</code></pre>

<p>Template :</p>

<pre><code>{% url 'elus' council='CFVU' %}
</code></pre>

<p>I've tried with <code>**kwargs</code> and other things. It work with <code>**kwargs</code> in another function with <code>&lt;pk&gt;</code> in url, and my query is based on the <code>id</code>. But here, with a string I can't find the solution.</p>

<p>You have <code>[A-B]</code> will only match the letters A and B. </p>

<p>If you only want to match uppercase letters you could do:</p>

<pre><code>url(r'^elus/(?P&lt;council&gt;[A-Z]+)$
</code></pre>

<p>Or, a common approach is to use <code>[\w-]+</code>, which will match upper case A-Z, lowercase a-z, digits 0-9, underscores, and hyphens:</p>

<pre><code>url(r'^elus/(?P&lt;council&gt;[\w-]+)$
</code></pre>

python django url