A
A
alex_deerk2016-07-23 18:46:16
Django
alex_deerk, 2016-07-23 18:46:16

Django why url not working?

url.py:

url(r'^other/(?P<category>[\w\-]+)/(?P<subcategory>\d+)/$', views.other_category, name='other_subcategory'),

In the template, the link looks like this:
{% url 'other_subcategory' cat sub.id %}
On one page, such a link:
/other/appliances/13/
On the other, this:
/other/master-tools/7/
From the transitions to the second, everything is as intended, but the first cannot find the required url :
NoReverseMatch at /other/appliances/13/
Reverse for 'other_subcategory' with arguments '('', 10)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['other/(?P[\\w\\-]+)/(?P\\d+)/$']
Request Method: GET
Request URL: 127.0.0.1:8000/other /appliances/13
Django Version: 1.9.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'other_subcategory' with arguments '('', 10)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['other/(?P[\\w\\-]+)/(?P\\d+)/$']

Through kwargs, I also tried to determine the link
{% url 'other_subcategory' category=cat subcategory=sub.id %}

NoReverseMatch at /other/appliances/13/
Reverse for 'other_subcategory' with arguments '()' and keyword arguments '{'subcategory': 10, 'category': ''}' not found. 1 pattern(s) tried: ['other/(?P[\\w\\-]+)/(?P\\d+)/$']
Request Method: GET
Request URL: 127.0.0.1:8000/other /appliances/13
Django Version: 1.9.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'other_subcategory' with arguments '()' and keyword arguments '{'subcategory': 10, 'category': ''}' not found. 1 pattern(s) tried: ['other/(?P[\\w\\-]+)/(?P\\d+)/$']

It's not clear to me where it gets 10 there. I suspect the answer is obvious as always, but I don't see it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oscar Django, 2016-07-23
@winordie

I suspect that everything is fine with the first link, the problem is with the link that should be on the page with the url /other/appliances/13/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question