Use replace header instead of push

This commit is contained in:
Daoud Clarke 2023-11-05 21:52:09 +00:00
parent 8293a7afa4
commit e3371233b5

View file

@ -49,13 +49,15 @@ def profile(request):
def search_results(request):
query = request.GET["query"]
results = ranker.search(query)
rendered = render(request, "results.html", {"results": results, "query": query})
response = render(request, "results.html", {"results": results, "query": query})
current_url = request.htmx.current_url
# Replace query string with new query
stripped_url = current_url[:current_url.index("?")] if "?" in current_url else current_url
query_string = "?q=" + query if len(query) > 0 else ""
new_url = stripped_url + query_string
return push_url(rendered, new_url)
# Set the htmx replace header
response["HX-Replace-Url"] = new_url
return response
def fetch_url(request):