Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

Just pass the parameters that have been defined in url as below:

<a href="{% url 'category' gender_slug=gender category_slug=category %}">{{category.name}}</a>

For more information refer to official docs

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading