# NoReverseMatch problems

**URL:** <https://forum.djangoproject.com/t/noreversematch-problems/18065>\
**Category:** Templates & Frontend\
**Created:** [January 8, 2023, 3:48am UTC](https://forum.djangoproject.com/t/noreversematch-problems/18065 "2023-01-08T03:48:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaClPhantom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/naclphantom/32/11650_2.png) [@NaClPhantom](https://forum.djangoproject.com/u/NaClPhantom)\
**Post date:** [January 8, 2023, 3:48am UTC](https://forum.djangoproject.com/t/noreversematch-problems/18065/1 "2023-01-08T03:48:23Z")

</div>

When I run the app (after already creating the diff categories and sub-categories in the admin page) I try to click on the categories link on the nav-bar and they show up, however, the problem is when i click on the specific category link. Here is when it sends the NoReverseMath error. The following image is an image from my terminal showing the error:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/4/427589a28a8ab1ee21023c9ef7f51b2817622835.png)

The following is my code:  
Thanks in advance!

urls.py (app folder)

```auto
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home,name="home"),
    path('items',views.all_items,name="list_items"),
    path('categories',views.category,name="categories"),
    path('show_category/<category_id>', views.show_category,name="show_category"),
]

```

models.py

```auto
from django.db import models
from django.urls import reverse
import uuid

# Create your models here.
class ClothingItem(models.Model):
    category = models.ForeignKey('Categorie',null=True,on_delete=models.CASCADE)
    sub_category = models.ForeignKey('SubCategorie',null=True,on_delete=models.CASCADE)
    name = models.CharField( max_length=50)
    brand = models.ForeignKey('Brand',null=True,on_delete=models.CASCADE)
    description = models.TextField(max_length=1000,blank=True)

    def __str__ (self):
            return self.name
 
    def get_absolute_url(self):
        return reverse("clothingitem_detail", kwargs={"pk": self.pk})

class Categorie(models.Model):
    category = models.CharField(max_length=100)
    def __str__ (self):
        return self.category
        
class SubCategorie(models.Model):
    sub_category = models.CharField('Clothing Type',max_length=100)
    def __str__ (self):
        return self.sub_category
    
    

class Brand(models.Model):
        brand_name = models.CharField(max_length=100)
 
        class Meta:
            ordering = ['brand_name']
 
        def get_absolute_url(self):
            return reverse("brand_detail", kwargs={"pk": self.pk})
 
        def __str__ (self):
            return self.brand_name

```

views.py

```auto
from django.shortcuts import render
from .models import ClothingItem,Categorie,SubCategorie

# Create your views here.

def home(request):
    return render(request,'item_type/home.html',{})

def show_category(request, category_id):
    category = Categorie.objects.get(id=category_id)
    sub_category = SubCategorie.objects.all()
    context = {'category':category,'sub_category':sub_category}
    return render(request, 'item_type/show_category.html',context)

def all_items(request):
    items_list = ClothingItem.objects.all()
    return render(request, 'item_type/clothing_list.html',{'items_list':items_list})

def category(request):
    category_list = Categorie.objects.all()
    return render(request, 'item_type/categories.html',{'category_list':category_list})

```

base.html

```auto
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Notte e Mattina</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
  </head>
  <body>
    {% include 'item_type/navbar.html' %}
    <br/>
    <div class="container">
    {% block content %}
    {% endblock %}
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
  </body>
</html>

 

```

categories.html

```auto
{% extends 'item_type/base.html' %}

{% block content %}
<h1>Categories</h1>
    {% for i in category_list %}
       <a href="{% url 'show_category' category.id %}"> {{i}}</a>
    {% endfor %}
{% endblock %}

```

clothing\_list.html

```auto
{% extends 'item_type/base.html' %}

{% block content %}
    <h1>List of items</h1>
    <br/>
    
        {% for i in items_list %}
            <div class="card">
                <div class="card-header">
                    {{i}}
                </div>
                <div class="card-body">
                <h5 class="card-title">{{i.sub_option}}</h5>
                <p class="card-text"> <strong> Brand: {{i.brand}} </strong>
                    <br/>{{i.description}}</p>
                </div>
            </div>
                <br/>
                <br/>
        {% endfor %}
    
{% endblock %}

```

home.html

```auto
{% extends 'item_type/base.html' %}

{% block content %}
<h1>hello</h1>
{% endblock %}

```

navbar.html

```auto
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
      <a class="navbar-brand" href="{% url 'home' %}">Notte e Mattina</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <a class="nav-link" href="{% url 'categories' %}">Categories</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'list_items' %}">All Items</a>
          </li>
        </ul>
        <form class="d-flex" role="search">
          <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success" type="submit">Search</button>
        </form>
      </div>
    </div>
  </nav>

```

show\_category.html (im still working on this specific view and page)

```auto
{% extends 'item_type/base.html' %}

{% block content %}
    <h1>{{category}}</h1><br/>
    {% for i in sub_category %}
        {{i}}
    {% endfor %}
{% endblock %}

```

---

<div class="post-metadata">

**Author:** ![NaClPhantom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/naclphantom/32/11650_2.png) [@NaClPhantom](https://forum.djangoproject.com/u/NaClPhantom)\
**Post date:** [January 8, 2023, 3:50am UTC](https://forum.djangoproject.com/t/noreversematch-problems/18065/2 "2023-01-08T03:50:28Z")

</div>

![Screenshot 2023-01-07 214942](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/0/0482948eb07bfc6ae21abff7aaa3dfda471d402b.png)

Sorry for not adding it in the original post, here too is another picture of the error directly from the page

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 8, 2023, 3:56am UTC](https://forum.djangoproject.com/t/noreversematch-problems/18065/3 "2023-01-08T03:56:08Z")

</div>

> [@NaClPhantom](#):
>
> ```auto
> {% for i in category_list %}
> <a href="{% url 'show_category' category.id %}"> {{i}}</a>
> {% endfor %}
> 
> ```

The identifier `category` does not exist at that line. I’m going to guess that you probably want `i.id` based upon the identifier you’re using in your loop.

---

<div class="post-metadata">

**Author:** ![NaClPhantom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/naclphantom/32/11650_2.png) [@NaClPhantom](https://forum.djangoproject.com/u/NaClPhantom)\
**Post date:** [January 8, 2023, 4:03am UTC](https://forum.djangoproject.com/t/noreversematch-problems/18065/4 "2023-01-08T04:03:41Z")

</div>

Thank you very much, it worked! And also thank you for the very prompt reply!
