Django 5.1.4
Python 3.12.4
HTMX 2.0.0
Goal:
Click an HTMX button and get / return / display a new value from a view function without refreshing entire page. I know it’s something stupid wrong I don’t see. I have not done this before inside of a card but code I’m using elsewhere that works is not working here.
Problem:
Response value is not displaying at all. The value as you can see from the response below is getting there to the correct element but does not display at all.
I have an HTML page with bootstrap 5 cards across the top and a chart below that. Basically a dashboard.
I have an input element inside one of the cards. There is also a HTMX button (see below).
html / htmx code
<div>
<input type="text" id="my-input" value="{{ msg_cnt }}">
<button class="btn-sm btn btn-outline-primary" hx-get="{% url 'console_app:console_flash_data' %}" hx-target="#my-input" hx-swap="innerHTML">Update</button>
</div>
views.py
def console_flash_data(request): # this function gets the data from ManagerMessages (model is in turnover_app)
template = 'console_app/base_console_ap.html'
if request.htmx:
msg_cnt = ManagerMessages.objects.filter().count()
context = {} # define context
context['msg_cnt'] = msg_cnt
else:
print("console_flash_data is Not an HTMX request :")
return render(request, template, context) # , {'form': form,'tologs': tologs,})
response return
<div>
<input type="text" id="my-input" value="4">
<button class="btn-sm btn btn-outline-primary" hx-get="/console_app/console_flash_data/" hx-target="#my-input" hx-swap="innerHTML">Update</button>
</div>