0
votes

Error: Page not found (404) Request Method: GET Request URL: http://localhost:8000/men/ Raised by: app.views.productinshop No Shop matches the given query.

urls.py

urlpatterns += patterns('',

url(r'^$', 'app.views.shop', name='shop'),
url(r'^shops/$', 'app.views.shops', name='shops'),
url(r'^(?P<shop_slug>[-\w]+)/$', 'app.views.productinshop', name='productbyshop'),
url(r'^(?P<shop_slug>[-\w]+)/(?P<gender_slug>[-\w]+)/$', 'app.views.shopandgender', name='shopandgender'),
url(r'^(?P<shop_slug>[-\w]+)/(?P<gender_slug>[-\w]+)/(?P<catalog_slug>[-\w]+)/$', 'app.views.shopgenderandcatalog', name='shopgenderandcatalog'),
url(r'^(?P<shop_slug>[-\w]+)/(?P<gender_slug>[-\w]+)/(?P<catalog_slug>[-\w]+)/(?P<category_slug>[-\w]+)/$', 'app.views.shopgendercatalogandcategory', name='shopgendercatalogandcategory'),
url(r'^(?P<product_slug>[-\w]+)/$', 'app.views.productdetails', name='productdetails'),
url(r'^(?P<gender_slug>[-\w]+)/$', 'app.views.gender', name='gender'),

)

1

1 Answers

0
votes

In Django, url patterns are matched in the order they are listed, and after the first match is found, no further searching is done.

In your case, you have three exact same patterns:

url(r'^(?P<shop_slug>[-\w]+)/$', 'app.views.productinshop', name='productbyshop'),
url(r'^(?P<product_slug>[-\w]+)/$', 'app.views.productdetails', name='productdetails'),
url(r'^(?P<gender_slug>[-\w]+)/$', 'app.views.gender', name='gender'),

When django sees http://localhost:8000/men/ the very first pattern that matches is the one that points to app.views.productinshop, so django stops searching further and that's the view that gets called.

To prevent this, you need to change your url schemes.