There are cases where I would like to not return any HTML in my view. Is there a good way to do it apart from returning a blank html file?
Here is what I have currently:
views.py
def get_suites(request):
address = request.GET.get( address )
rental_units = Rental_Unit.objects.filter(address__address=address).order_by( suite )
# return empty html requests
if len(rental_units) > 1:
return render(request, suite_list.html , { rental_units : rental_units})
else:
return render(request, empty.html )
suite_list.html
<label for="suite">Suite</label>
<select name="suite" id="suite">
<option value="all">All</option>
{% for rental_unit in rental_units %}
<option value="{{rental_unit.suite}}">{{rental_unit.suite}}</option>
{% endfor %}
</select>
main.html
<label for="address">Address</label>
<select name="address" id="address" hx-get="/get_suites" hx-target="#suite-wrapper">
<option value="all">All</option>
{% for address in addresses %}
<option value="{{address}}">{{address}}</option>
{% endfor %}
</select>
<div id="suite-wrapper" style="display:inline"></div>