Greas Le mer. 29 nov. 2023, 11:57, Thomas Couch <[email protected]> a écrit :
> 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? > https://htmx.org/examples/progress-bar/ > > > 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 >> >> >> @property >> >> 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 }} "/> >> >> </div> >> >> <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 https://htmx.org/docs/#polling >> >> 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. >> >> Cheers >> >> Mike >> >> -- > 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/020a98ef-4a10-4560-afdd-0a8b065e7235n%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/020a98ef-4a10-4560-afdd-0a8b065e7235n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CACCiQ-kXKdgpS%3DCAK0ZJXrw6JO4CXVftcjpiP%3D2E3rh1NgqD3g%40mail.gmail.com.

