Reputation: 749
my template:
<form action="{% url 'student:filter' %}" method='get'>
<select>
<option value="00">----</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sept</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</form>
views.py:
def filter(request, value):
value = request.GET['value']
att = Attendancename.objects.filter(date__hours=int(value))
return render(request, 'listfilter.html', {'attend': att})
urls.py:
url(r'^filter/(?P<value>\d+)$', views.filter, name = 'filter'),
What I want is to select a particular month from above html drop down, and its corresponding value needs to be passed in my views.py through url's argument, which then used in a look-up query.
But things are not working as I want. I'm doing something wrong with my templates, I don't know exactly how to trigger action corresponding to selected value in drop down.
Please! Can anybody tell me how to make it correct?
Thanks! in advance....
Upvotes: 0
Views: 52
Reputation: 599630
Don't try and pass this data in the slug. In this case use the query string, which will be appended automatically by the browser for a GET.
<form action="{% url 'student:filter' %}" method='get'>
<select name="filter">
...
def filter(request):
value = request.GET['value']
url(r'^filter/$', views.filter, name = 'filter'),
Upvotes: 1