'Django href for html

How i can make link to this urls.py? I tried to pass the link through all the methods I know but they don't work and gave an error

    path('category/<slug:gender_slug>/<slug:category_slug>/', views.StuffCategory.as_view(), name='category'),

html:

{% get_genders as genders %}
                    {% for gender in genders %}
                <li>
                    <!-- First Tier Drop Down -->
                    <label for="drop-2" class="toggle">Категории <span class="fa fa-angle-down"
                                                                       aria-hidden="true"></span> </label>

                    <a href="/">{{ gender }} <span class="fa fa-angle-down" aria-hidden="true"></span></a>
                    <input type="checkbox" id="drop-2">

                    <ul>
                        {% get_categories as categories %}
                        {% for category in categories %}
                        <li><a href="/">{{category.name}}</a></li>
                        {% endfor %}
                    </ul>
                </li>
                    {% endfor %}

views.py

class StuffCategory(ListView):
    model = Stuff
    template_name = 'shop/shop.html'
    context_object_name = 'stuffs'

    def get_queryset(self):
        queryset = Stuff.objects.filter(draft=False)
        if self.kwargs.get('category_slug'):
            queryset = queryset.filter(category__slug=self.kwargs['category_slug'])
        if self.kwargs.get('gender_slug'):
            queryset = queryset.filter(gender__slug=self.kwargs['gender_slug'])
        return queryset


Solution 1:[1]

When trying to access a link with a href attribute you can simply use the name attribute of your path object that you defined in urls.py. You have to make sure, to submit every parameter the path object needs:

For example for an edit field:

<li><a href="{% url 'category' object.pk gender_slug=gender arg %}">

here:

  • category is the name
  • object.pk could be the primary key of the object transmitted to the template
  • gender_slug & arg are additional parameters that are defined by your path object

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xtlc