0

I'm having some problem with my url in Django (1.9)

Tried many way to solve it, but still the same type of error

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

The actual code is this :

View :

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)

url :

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

Template :

{% url 'elus' council='CFVU' %}

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

1 Answer 1

1

You have [A-B] will only match the letters A and B.

If you only want to match uppercase letters you could do:

url(r'^elus/(?P<council>[A-Z]+)$

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

url(r'^elus/(?P<council>[\w-]+)$
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, and sorry for the waste of time ... This error was really stupid error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.