Link does not work, throwing NoReverseMatchError

NoReverseMatch at /category/1/
Reverse for 'category' with arguments '('',)' not found. 1 pattern(s) tried: ['category/(?P<category_id>[0-9]+)/

This error is displayed when navigating to a site category from the home page. On googling I found that my url does not match the url in the template and django reports it. But I still don’t understand what is wrong, because everything is written to match the urls.py templates.

urls.py(app folder)

from django.urls import path
from .views import *


urlpatterns = [
    path('', home_page, name='home_page'),
    path('category/<int:category_id>', get_category, name='category'),
    path('news/<slug:slug>', view_news, name='news'),
]

urls.py(project folder)

import debug_toolbar
from django.contrib import admin
from django.urls import include, path
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('news.urls')),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('__debug__/', include(debug_toolbar.urls)),
]

base.html

{% load news_tags %}

{% get_all_categories as categoies %}
   {% for category in categoies %}
      <li><a href="{% url 'category' category.pk %}" class="nav-link px-2" style="color: rgb(179, 179, 179);">{{ category.title }}</a></li>
   {% endfor %}

index.html(home page)

{% for item in page_obj %}
        <div class="card mb-5">
          <div class="card-header">
            <div class="category_name"> <a href="{% url 'category' item.category_id %}" style="text-decoration: none; color: rgb(93, 92, 92);">{{ item.category }}</a> - {{ item.created_at }}</div>
          </div>
          <a href="/news/{{ item.slug }}" style="text-decoration: none; color: rgb(26, 25, 25);">
            <div class="card-body">
              <h3 class="card-title">{{ item.title }}</h3>
              <p class="card-text">{{ item.content|linebreaks|truncatewords:50 }}</p>
            </div>
          </a>
        </div>
{% endfor %}

views.py

def home_page(request):
    all_publicated_blogs = News.objects.filter(is_published=True,)

    return render(request, 'news/index.html', 
                  {'page_obj': Pagination(request, all_publicated_blogs).pagination(10),})


def get_category(request, category_id):
    news_by_category = News.objects.filter(category_id=category_id, is_published=True)
    one_news = news_by_category[0]
    
    return render(request, 'news/category.html', 
                  {'page_obj': Pagination(request, news_by_category).pagination(10), 'news': one_news,})

models.py

from django.db import models
from ckeditor.fields import RichTextField


class News(models.Model):

    title = models.CharField(max_length=50,verbose_name='Заголовок',)
    content = RichTextField()
    created_at = models.DateTimeField(auto_now_add=True,verbose_name='Дата Создания')
    updated_at = models.DateTimeField(auto_now=True)
    is_published = models.BooleanField(default=False, verbose_name='Опубликовано')                    
    category = models.ForeignKey('Category', on_delete=models.PROTECT, null=True, verbose_name='Категория')
    slug = models.SlugField(verbose_name='URL', max_length=40, unique=True,)


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'Новость'
        verbose_name_plural = 'Новости'
        ordering = ['-created_at']


class Category(models.Model):
    title = models.CharField(max_length=50, db_index=True,
                             verbose_name='Название категории')                         

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'Категорию'
        verbose_name_plural = 'Категории'
        ordering = ['id']

news_tags.py

from django import template
from news.models import Category


register = template.Library()


@register.simple_tag()
def get_all_categories():
    return Category.objects.all()

category.html

{% get_all_categories as categoies %}
            {% for category in categoies %}
                {% if category == news.category %}
                  <li><a href="{% url 'category' category_id=category.pk %}" class="nav-link px-2" style="color: white;display: inline; padding: 17px 6px; border-bottom: solid 5px #707990;">{{ category.title }}</a></li>
                {% else %}
                  <li><a href="{% url 'category' category_id=category.pk %}" class="nav-link px-2" style="display: inline; padding: 0px 6px;">{{ category.title }}</a></li>
                {% endif %}
            {% endfor %}
```]

This is not the right syntax for that statement.

You had it right earlier in your post:
<a href="{% url 'category' category.pk %}" class="nav-link px-2" style="color: rgb(179, 179, 179);">

Hello @error_404 and @KenWhitesell . I don’t want to hijack someone else’s question. I can certainly post a new one, but I jumped in here because I am having almost exactly the same issue. In fact, a day or two ago I switched from path() to re_path() in hopes of fixing it, but after a lot of time and work the best I could do was get back to exactly the same issue.
In my case, I am trying to go from a list to a detail page, which sounds like what error404 is doing. His home page might not be a list, but the problem comes because his home template has a url tag in it, just like a list would - or most any page, for that matter. That makes this a HUGE problem. I laid out my issues in detail on SO here: python - re_path syntax in *application* urls.py - Stack Overflow I was going to come here and post but I had to close the browser and got sidetracked and forgot :frowning: .
I don’t know what error404’s experience is, but Ken, I tried your solution and still got the same result. :sob:

One more bit of info for both of you, and anyone else who may come here: There is a known bug at work here: Re: [django/django] Fixed #28935 – Fixed display of errors in extended blocks. (#14367). This bug is not directly responsible for the issue - I don’t think - ??? - But it does directly impact the ability to debug it. The core dev who responded to me said the patch they just got will not go in until 4.0!!! There is of course the option of patching it yourself, which I have thus far tried to avoid.

As it is most likely a different issue with a different cause and solution, I would encourage you to post a new topic here.

Ok. Done: https://forum.djangoproject.com/t/re-path-syntax-in-application-urls-py/9474
Thanks!