I have an error:
The current path, search_shop/5ka/, didn't match any of these.
Reason of the problem is name of the slug field 5ka
. When I changed name from 5ka
to pka
it works fine.
How can I use 5ka
without errors?
models.py
class Shop(models.Model):
title = models.CharField(max_length=200)
image = models.ImageField(blank=True)
slug = models.SlugField(null=False, default="Shop") # I mean this field
def get_search_url(self):
return reverse('search_shop', kwargs={'slug': self.slug})
urls.py
urlpatterns = [
path('', HomePageView.as_view(), name='main_list'),
path('search/', SearchResultsView.as_view(), name='search_results'),
path('search_shop/<slug:slug>', ProductListView.as_view(), name='search_shop'),
path('search_shop_results/<slug:slug>/', ProductSearchResultsView.as_view(), name='search_shop_results'),
path('<slug:slug>/<int:pk>/', views.product_detail, name='product_detail'),
path('shops/', ShopListView.as_view(), name='shop_list'),
]
shop_list.html
{% for shop in shops %}
<a href="{{ shop.get_search_url }}"
just include a /
in the following line it will be resolved
path('search_shop/<slug:slug>/', ProductListView.as_view(), name='search_shop'),
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments