https://htmx.org logo
Join Discord
Powered by
# πŸ”₯-django-htmx
  • m

    mysterious-toddler-20573

    08/05/2021, 1:47 PM
    is this example helpful? https://htmx.org/examples/active-search/
  • u

    user

    08/05/2021, 2:47 PM
    Thank you, I have already seen that. My problem is I have no clue where it start to integrate it.
  • u

    user

    08/05/2021, 2:57 PM
    To be more concrete. The select field is a model choice field.
  • v

    victorious-room-74725

    08/05/2021, 3:34 PM
    You'll probably want to have a view that returns the HTML that will replace the default select.
  • v

    victorious-room-74725

    08/05/2021, 3:35 PM
    and then have the hx-target replace the contents of the original select
  • v

    victorious-room-74725

    08/05/2021, 3:37 PM
    I think that's pretty much it.
  • u

    user

    08/05/2021, 6:16 PM
    I have somethign that might help
  • u

    user

    08/05/2021, 6:16 PM
    Views: https://github.com/Tiny-Tiny-App/tinytinylog/blob/develop/log/views.py#L221
  • u

    user

    08/05/2021, 6:16 PM
    Templates: https://github.com/Tiny-Tiny-App/tinytinylog/blob/develop/log/templates/search.html
  • u

    user

    08/05/2021, 6:17 PM
    Class based views: https://github.com/Tiny-Tiny-App/django-htmx-extras/tree/main/django_htmx_extras/views/generic
  • u

    user

    08/05/2021, 6:18 PM
    And specifically this Mixin: https://github.com/Tiny-Tiny-App/django-htmx-extras/blob/main/django_htmx_extras/views/generic/base.py#L5
  • u

    user

    08/05/2021, 6:19 PM
    Same pattern but another app: https://github.com/Tiny-Tiny-App/tinytinydirectory/tree/develop
  • u

    user

    08/05/2021, 6:19 PM
    this one is very much a WIP, but the htmx side of things can be considered as done.
  • u

    user

    08/05/2021, 6:20 PM
    Do note that they are using
    django-crispy-forms
  • u

    user

    08/05/2021, 6:20 PM
    But not using
    django-crispy-forms
    actually makes your code a little simpler
  • u

    user

    08/06/2021, 6:24 AM
    Thank you all for you help. Will have a look at it!
  • s

    steep-caravan-97347

    08/08/2021, 3:53 PM
    Hello, I’m implementing htmx into a django quizz app and have a div who shows the remaining time (
    Copy code
    <div hx-get="{% url 'quizzes:attempt-remaining-time' attempt.id %}"
         hx-trigger="every 5s"
         …
    >
    ), and another div listing all the questions. I would like this last div to be reloaded when the time is over, by a Hx-trigger event from the remaining-time View for example, but I’m a bit stock with how is the best way to make it… would you guys have some thoughts or ideas ? Thanks !
  • v

    victorious-room-74725

    08/08/2021, 4:30 PM
    Maybe have your remaining time view return something with an hx-trigger to replace the questions.
  • v

    victorious-room-74725

    08/08/2021, 4:30 PM
    if the remaining time <= 0
  • m

    mysterious-toddler-20573

    08/08/2021, 4:49 PM
    Copy code
    html
      <div hx-get="/whatever" hx-trigger="load delay:<%= time_remaining %>" ...>...</div>
  • u

    user

    08/08/2021, 11:11 PM
    Just to validate a point here: I have a form that, on submit, saves the data and redirects (using Django redirect) to the form view again. Before redirecting, I set a
    HX-Trigger
    header. Should htmx handle this header as it's not a
    200
    response?
  • m

    mysterious-toddler-20573

    08/08/2021, 11:26 PM
    unfortunately htmx doesn't see the response before the redirect
  • u

    user

    08/08/2021, 11:39 PM
    Why redirect? See: https://github.com/Tiny-Tiny-App/tinytinylog/blob/develop/log/views.py#L122
  • u

    user

    08/09/2021, 9:57 AM
    Unfortunately, my use case is a little bit more complex. To render the form I need to put some stuff in the context to generate list options. I want to avoid having to generate these lists in different places (on form initialization and on form validation errors).
  • s

    salmon-xylophone-28580

    08/12/2021, 2:50 PM
    With htmx the old post-redirect-get pattern is not needed any more. CBV redirect by default. That's one reason I switched to FBV. Maybe this helps you https://github.com/guettli/django-htmx-fun#naming-pattern
  • s

    shy-ability-59156

    08/12/2021, 6:17 PM
    @User thanks for pointing me indirectly at your django-tips repo πŸ™‚ I didn't kow about WhiteNoise.
  • u

    user

    08/13/2021, 1:27 AM
    @User I see your point. You don't redirect, you have a reusable "form render" function. Nice.
  • u

    user

    08/19/2021, 7:58 AM
    is there any thing should i keep in mind when using htmx with new added html using jquery ajax ! cuz it fails to trigger htmx inside this newly added content
  • m

    mysterious-toddler-20573

    08/19/2021, 2:08 PM
    https://discord.com/channels/725789699527933952/725789747212976259/877916454593392661
  • m

    millions-morning-77621

    08/21/2021, 5:19 AM
    how do I do infinite scroll with django??
12345...100Latest