Skip to content
Advertisement

Using Javascript to implement Live Django Search

I am adding a Search functionality to my E-commerce Project using Javascript, I have followed a tutorial that explains that when writing the title in the search bar only the items with the same letter appears. In my project, it was working fine for basic HTML but I am trying to make it a little more complex to include a complete card with some details such as price, not just the title.

Here is the model.py

JavaScript

Here is the views.py

JavaScript

Here is the scripts.py

JavaScript

Here is the template.html

JavaScript

My Question: How do I replace the simple <b>${store['title']}</b><br> with the below in the scripts with the whole card div with all its information related to it?

If any more information or clarifications required let me know

JavaScript

Advertisement

Answer

Your template.html page already have all htmls generated using for-loop so you don’t need to generate them again .Instead , when user type you can loop through all div and check if card-title div has that input if it has simply show that div or else hide it.

Demo Code :

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement