-1

NoReverseMatch at / Reverse for 'Jersey' with no arguments not found. 1 pattern(s) tried: ['Jersey/(?P[^/]+)/$']

Below is the code to my views.py

class JerseyView(TemplateView):
        #paginate_by=3
     template_name='Ecommerce/Jersey.html'
    
     def get_context_data(self, **kwargs):    
         et =super(JerseyView, self).get_context_data(**kwargs)
         et['United']= Item.objects.filter(category="3").filter(subcategory="9")
         et['Chelsea']= Item.objects.filter(category="3").filter(subcategory="10")
         return et 

below is the code for my urls.py

path('Jersey/<slug>/', JerseyView.as_view(), name="Jersey" ),

I called This link in my Navbar as

<a class="dropdown-item" href="{% url 'Ecommerce:Jersey' %}">Men's Clothing</a>

when I click on it it gives me the error as NoReverseMatch at / Reverse for 'Jersey' with no arguments not found. 1 pattern(s) tried: ['Jersey/(?P[^/]+)/$'] I don't know if there's something i am missing out because i have checked my spelling and still getting the same error

prof lord
  • 1
  • 4

2 Answers2

0

By using {% url 'Ecommerce:Jersey' %}, you're trying to access Jersey/<slug> path without giving any argument. So Django router expect a argument on this path (slug).

You need to provide it, (only you knows what slug goes there...) like this :

{% url 'Ecommerce:Jersey' Jersey.slug %}

Guillaume
  • 1,956
  • 1
  • 7
  • 9
0

is this slug dynamically change or not? if it is then first you should correct your url like this: 'Jersey/<slug:slug>/' and in href tag, get slug from context you passed in views.py like what user BriseBalloches said. but if your slug is a fixed parameter, you can just write it in href tag. suppose your slug parameter is country then your href tag should work with href="Jersey/country" or href="{% url 'Ecommerce:Jersey'country %}"

these href tags will generate http://127.0.0.1:8000/Jersey/country

Reza GH
  • 1,504
  • 1
  • 8
  • 16
  • The slug dynamically changes I just added the Jersey/slug:slug into my urls how should it be rendered in the template? Something like app_name:Jersey Jersey.slug? – prof lord Dec 27 '20 at 14:22
  • aren't you using link in navbar? then why and how it should change dynamically . can you share your any desk address?? – Reza GH Dec 27 '20 at 14:25