Home > Enterprise >  How to **dynamically display** different pages using one html page
How to **dynamically display** different pages using one html page

Time:07-20

I know I have asked this question before but I am really struggling on this issue.

I am currently making a shopping website using django and I want to dynamically display the data. The 'shoppingpage' lists the categories and subcategories of clothes. If I click on 9-6 wear, only the images of 9-6wear clothes should come. enter image description here

For example, as shown in the image above when I click on 9-6wear, I get images of 9-6 wear,but the issue is that when I click on other categories(like Fusion wear bridal wear desi swag), I get the same clothes as I got in 9-6 wear. How do I make sure that I get clothes belonging to 'bridal wear' when I click bridal wear and so on using django and html and displaying the data dynamically? below are the functions ,urls ,html pages url

path('category/',views.category,name="category")

function

def category(request):
    prod = Products.objects.filter(isactive=True)
    return render(request,'polls/category.html',{'products':prod})

category.html

{% for product in products %}
            <li  data-wow-duration="1s" data-wow-delay="0ms" data-wow="fadeInUp">
                <div >
                    <div >
                        <a href="{% url 'polls:productdetails' product.id %}" >
                            <img  src="{{product.image}}" alt="MINI SKIRT" width="400" height="400">
                        </a>
                    </div>
                    <div >
                        <h3 >
                            <a href="/products/details/65">{{product.title}}</a>
                        </h3>
                        <span >
                            <span >
                                <ins>
                                    <span >₹</span>
                                    <span >
                                        {{product.price}}
                                    </span>
                                </ins>
                            </span>
                        </span>
                    </div>
                </div>
        
            </li>
{% endfor %}

I have added 'isactive' because I am doing soft delete help is greatly appreciated thanks!

CodePudding user response:

just add following to your urls and views

path('category/<int:category_id>/', views.category_detail, name='category'

your function

def category_detail(request, category_id):
    prod = Products.objects.filter(isactive=True, category_id=category_id)
    return render(request,'polls/category.html',{'products':prod})
  • Related