Can't redirect to category list url - django

127 Views Asked by At

I can't figure out how can I redirect to category list page but url is working fine i just can't add correct redirect url by id into href tag :(

html

<div class="widget widget-catgs">
  <h3 class="widget-title">Categories</h3>
  <ul>

    {% for cat in category %}
    <li>
      <a href="**{% url 'category-list' property.category.id %}**" title=""><i
          class="la la-angle-right"></i><span>{{ cat.category__title }}</span></a>
      <span>{{ cat.category__title__count }}</span>
    </li>
    {% endfor %}

  </ul>
</div>

views.py

def property_by_category(request, category_id):
    property_list = Property.objects.all()
    category = get_object_or_404(Category, pk=category_id)
    category_list = Property.objects.filter(category=category)

    context = {
        'category_list': category_list,
        'category_name': category,
        'property': property_list
    }
    return render(request, 'property/property-category.html', context)

urls.py

urlpatterns = [
    path('', views.property, name='property-page'),
    path('details/<int:property_id>', views.property_details, name='property-details'),
    path('category/<int:category_id>', views.property_by_category, name='category-list'),
    path('add-property/', views.add_property, name='add-property'),
]

I'm learning django, please take a look at my code.

0

There are 0 best solutions below