I'm trying to implement the active search functionality with htmx but am
getting a server error. I'd really appreciate any help on this. Googling
the problem resulted in people either not using return before render or an
indentation problem. I've checked these.
Thanks in advance,
Brian
```
ValueError: The view Striker.views.search_player didn't return an
HttpResponse object. It returned None instead.
```
view.py
```
def search_player(request):
print(request)
search_text = request.POST.get("search")
results = Player.objects.filter(name__icontains=search_text)
context = {'results': results}
return render(request, 'Striker/partials/player-search-results.html',
context)
```
player-search-results.html
```
{% if results %}
{% csrf_token %}
{% for player in results %}
<div class="box-border h-85 w-60 mb-1">
<div class="mx-2 rounded-lg border-double border-2 border-emerald-500
px-2 py-2 bordermildblue">
<div class="bg-gray-800">
<h2 class="text-blue-400 text-lg title-font font-medium mb-4
button-85"><a
href="{% url 'player.detail' player.pk %}" title="Link to
Player's Toons">{{ player.name }}</a>
</h2>
</div>
<div class="text-left">
<p class="leading-relaxed text-base">GP: {{ player.gp|intword
}}</p>
<p class="leading-relaxed text-base">Toons: {{
player.gpChar|intword }}</p>
<p class="leading-relaxed text-base">Ships: {{
player.gpShip|intword|intcomma }}</p>
<p class="leading-relaxed text-base">Allycode: <a
class="text-blue-500"
href="https://swgoh.gg/p/{{ player.allycode }}" Title="Link
to SWGOH.gg">{{ player.allycode }}</a>
<span class="text-xs">.gg</span>
</p>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No search results</p>
{% endif % }
```
called from
```
{% load humanize %}
<div class="d-flex justify-content-end mb-4">
<form>
{% csrf_token %}
<input type="text"
hx-post="{% url 'search-player' %}"
hx-target="#results"
hx-trigger="keyup changed delay:500ms"
name="search"
class="form-control-sm mr-2"
placeholder="Search players..." />
</form>
</div>
<div id="results">
</div>
```
urls.py
```
path('striker/search-player', views.search_player, name='search-player'),
```
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5c4eb0ed-8d4b-4294-83d3-1955b7b431b5n%40googlegroups.com.