I am at beginner level in django. And, I am unable to get the value of user selected option in view. I have to apply some logic there.
views.py
def shop(request):
if request.GET.get('featured'):
featured_filter = request.GET.get('featured')
print(featured_filter) #debugging purpose
else:
print("\n\nnone\n\n") #debugging purpose
bookz = Book.objects.order_by('title')
var = {'books': bookz, 'range': 10}
return render(request, 'bookrepo/shop.html', context=var)
shop.html
<form action="{% url 'bookrepo:shop' %}" method="GET">
<select name="featured" class="custom-select-lg custom-select">
<option selected><h1>Filter</h1></option>
<option value="pricelow">Low price</option>
<option value="pricehigh">High price</option>
<input type="submit" name="featured" value="Filter" />
</select>
</form>
These option things have nothing to do with models. So right now, I am getting this when I select low price and press button: (in django console)
[10/May/2020 00:18:20] "GET /shop/?featured=pricehigh&featured=Filter HTTP/1.1" 200 47486
[10/May/2020 00:18:20] "GET /static/js/js.dom.changer.js HTTP/1.1" 304 0
Filter
[10/May/2020 00:18:24] "GET /shop/?featured=pricelow&featured=Filter HTTP/1.1" 200 47486
As u can see "Filter" is getting printed. But i want is featured's value like pricelow or pricehigh.