Neha, try changing your template for loop from: {% for results in formdata %}
To: {% for results in search %} The name of your queryset in your context (d = {'search': search, 'fd': fd, 'td': td}) is search, not formdata. Also, I’d recommend improving your names. Things like “data” and “results” are not the most meaningful names to use. Good luck! Jim On Feb 16, 2021, at 1:57 AM, neha bhurke <bhurkene...@gmail.com<mailto:bhurkene...@gmail.com>> wrote: hi Everyone , I have created a application in which I want to filter table between dates (from and to)dates But not getting a desired output . This is my models.py class data(models.Model): machinename = models.CharField(max_length=100) activity = models.CharField(max_length=255) description = models.CharField(max_length=500) datetime = models.DateField() This is my html page <form method="POST"> {% csrf_token %} <center> <input type="text" id="search_all" placeholder="Search Machine.." style="width:250px; height:30px"> <hr/> >From :<input type="date" name="fromdate"/> To :<input type="date" name="todate"/> <input type="submit" value="Search" /> <hr/> <br> <div style="width:550px; height:350px; overflow:auto; "> <table border="4" bgcolor="grey"> <thead> <tr style="text-align:center; color:black; border:1px solid black; background-color: #f1f1f1;"> <th>Datetime</th> <th>Machine Name</th> <th>Activity</th> <th>Description</th> </tr> </thead> <tbody> {% for results in formdata %} <tr style="text-align:center; color:black; border:1px solid black"> <td>{{results.datetime}}</td> <td>{{results.machinename}}</td> <td>{{results.activity}}</td> <td>{{results.description}}</td> {% endfor %} </tr> </tbody> </table> </center> </form> This is my views.py def showresults(request): if request.method == "POST": fd = request.POST.get['fromdate'] td = request.POST.get['todate'] search = data.objects.filter(Q(datetime__gte=fd) & Q(datetime__lte=td)) d = {'search': search, 'fd': fd, 'td': td} return render(request, 'dashboard.html', d) else: result = data.objects.all() return render(request, 'dashboard.html', {'formdata': result}) Please help me.. Thank You !! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/11780FCE-6C09-4B48-A61D-42B3FA7FCCD7%40hotmail.com.