Reputation: 4316
This problem seems simple and it is described multiple times in SO, but I still can't figure out why it isn't working in my case.
So, I have a url declared in urls.py
urlpatterns = patterns('',
url(r'^(?P<country>[-\w]+)/$', CountryListView.as_view(), name='list_by_country'),)
and in my template I'm calling the url
<a href="{% url 'list_by_country' country.country__name %}" >{{ country.country__name }}</a>
However, I am getting the error message that the url could not be reversed
Reverse for 'list_by_country' with arguments '(u'United Kingdom',)' and keyword arguments '{}' not found
What is causing the reverse error? Are spaces in the argument maybe not allowed?
Upvotes: 1
Views: 2059
Reputation: 13058
The problem is that "United Kingdom" doesn't match the regex [-\w]+
. If you also want to match spaces, you should change your regex to [-\w\ ]+
. Example:
url(r'^(?P<country>[-\w\ ]+)/$', CountryListView.as_view(), name='list_by_country')
You can also choose to match \s
instead of just a single space character.
Upvotes: 5