Wednesday, November 29, 2023

Re: htmx progress indicator problem - might be caching

Not sure if it's related, but you've got a div inside a p element there:
<p><div hx-get="/hx_usr_progress" hx-trigger="every 1s"></div></p>

That'll probably get corrected by the browser to:
<p></p> <div hx-get="/hx_usr_progress" hx-trigger="every 1s"></div> <p></p>

Another thing is, it doesn't look like there's anything linking the submit button click to the initial htmx request, and there's no htmx in the response. Have you tried replicating the progress bar example?

On Tuesday, November 28, 2023 at 2:26:20 AM UTC Mike Dewhirst wrote:
I'm trying but failing to get htmx to deliver a progress indication.

The task is creating records in the database for each item in a list provided by the logged in user.

The view with the submit button collects the list and does the database insertion. I added a "progress" property to the User model as follows ...

class User(AbstractUser):
      def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.progress = ""
      def set_progress(self, value):
        self.progress = value
    def get_progress(self):
        return f"{self.progress}"

In the view I update user.progress with the record insertion counter and get_progress returns the correct value in the view itself as proven by print statements. So that part is working.

In the template, I have ...

  <div class="submit-row">
    <input type="submit" value="     {{ btn_label }}      "/>
  <p><div hx-get="/hx_usr_progress" hx-trigger="every 1s"></div></p>

... which in theory should fetch progress every second if the htmx docs are correct. See

This is the htmx view ...

def hx_usr_progress(request):
    progress = request.user.progress
    print(f"\n{progress} ... {request.user}")
    return HttpResponse(mark_safe(f"<p>... {progress}</p>"))

When the import [Submit] button is clicked, the print statement in hx_usr_progress fires with a blank progress value as per the User.__init__() method AND on the page beneath the Submit button the 3 dots shown above in the last line of the hx_usr_progress() view but nothing further even though the main view is definitely incrementing the count.

That tells me it is being called at least once instead of every second. It should have fired at least 3 or 4 times.

Or if it did perhaps the original response is cached - I don't know.

How can I get this ticking over?

Thanks for any hints.



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
To view this discussion on the web visit

No comments:

Post a Comment