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

    millions-morning-77621

    08/21/2021, 5:19 AM
    can't find anything on it
  • u

    user

    08/21/2021, 11:13 AM
    You can achieve it with any backend. There's an example at htmx.org site: https://htmx.org/examples/infinite-scroll/
  • m

    millions-morning-77621

    08/21/2021, 11:16 AM
    ohhh, okay, thanks, but is there a tutorial/article about this anywhere?
  • v

    victorious-room-74725

    08/21/2021, 7:38 PM
    This last element contains a listener which, when scrolled into view, will trigger a request. The result is then appended after it. The last element of the results will itself contain the listener to load the next page of results, and so on.
    I don't know. You will want an html fragment page which renders some sort of object_list from your context dictionary. And on the last element, it will need to add to the final tag
    Copy code
    hx-get="{% your url tag pointing to the paginated view %}/?page={{ #something for next page number }}"
        hx-trigger="revealed"
        hx-swap="afterend"
    You'll want this fragment view to be included (with the % include % tag) in your full page view. The full page view should open / close the table tag and inside it should include the first page of a view following what I described above.
  • v

    victorious-room-74725

    08/21/2021, 7:38 PM
    @User
  • v

    victorious-room-74725

    08/21/2021, 7:39 PM
    That's how I think it might look, haven't done this personally though.
  • i

    important-winter-64905

    08/23/2021, 2:27 PM
    Is there an example where someone does math with htmx? I need to update values in a database and then report the sum of those values. Ideally changing the value a clicking away (similar to https://htmx.org/examples/inline-validation/) submits updates to the database but I need the new data to be reflected in the sum elsewhere on my page.
  • m

    mysterious-toddler-20573

    08/23/2021, 2:29 PM
    sounds like you either want to target that other area using
    hx-target
    or potentially use an out of band swap to target it
  • i

    important-winter-64905

    08/23/2021, 2:48 PM
    I'm reading up on this now. I'm interesting is solution 3 here: https://htmx.org/examples/update-other-content/ as a potential option
  • u

    user

    08/23/2021, 5:52 PM
    https://mitchel.me/slippers/
  • i

    incalculable-scientist-18707

    08/24/2021, 11:00 PM
    I have a question about using alpine.js and htmx in a django app. I'm looping through an x-for in alpine and want to pass an alpine variable into x-bind:hx-vals = "{'myVal': 'My Value'}". Can this work?
  • i

    incalculable-scientist-18707

    08/24/2021, 11:34 PM
    OK...figured this out. It does work...but requires a bit of parsing:
  • i

    incalculable-scientist-18707

    08/24/2021, 11:34 PM
    :hx-vals="'{' + '\"' + 'myVal' + '\"' + ': ' + '\"' + alpine_variable + '\"' + '}' "
  • s

    salmon-xylophone-28580

    08/26/2021, 2:34 PM
    Doing math with htmx.... Htmx is declarative like html. You can do math with a programming language, but htmx is a markup language.
  • i

    important-winter-64905

    08/26/2021, 4:12 PM
    absolutely!. I'm thinking more along the lines of... user updates value in table >> POST request to Django >> update database and update new sum >> send response back to front-end
  • u

    user

    08/26/2021, 4:30 PM
    The view that call all those operations (update database, update new sum, etc.) should return the HTML element that contains the sum value with the updated value (new sum) so that htmx can swap it in you current page.
  • u

    user

    08/30/2021, 12:41 PM
    Django fellows: are you using Django Crispy Forms with htmx? Any issues? Tips?
  • u

    user

    08/30/2021, 6:32 PM
    Yes, I do use it. No issues
  • u

    user

    08/30/2021, 6:33 PM
    example: https://github.com/Tiny-Tiny-App/tinytinylog/blob/develop/log/forms.py#L35
  • u

    user

    08/30/2021, 6:33 PM
    you basically pass certain htmx props through the form class
  • u

    user

    08/30/2021, 6:37 PM
    Ow. Was looking for a more "templaty" solution.
  • u

    user

    08/30/2021, 9:14 PM
    Yeah I understand. Mine is hacky πŸ™‚
  • u

    user

    08/30/2021, 9:15 PM
    Overall id say the experience with htmx and crispy forms is good
  • v

    victorious-room-74725

    08/31/2021, 2:22 AM
    Hmm, this is the exact use case. You just use htmx to post to a django view which handles the post request and returns the value (or rendered html fragment). all the request/response / math / db stuff is going to be in the view side. If you're using class-based views, this one is probably more straightforward as a regular old function. You can start with hx-post and hx-target on the htmx side πŸ™‚
  • v

    victorious-room-74725

    08/31/2021, 2:25 AM
    which of these parts are you hitting a wall with?
  • v

    victorious-room-74725

    08/31/2021, 2:30 AM
    Oh, and maybe hx-include πŸ™‚
  • i

    important-winter-64905

    09/01/2021, 5:41 PM
    I’m just trying to wrap my head around an example of this in Django. I’ve seen the example on HTMX.org but it’s obviously missing the Django side of that. That’s what I’m missing (I think)
  • u

    user

    09/01/2021, 5:43 PM
    You shouldn't think about the technology. Think about request and HTML responses.
  • i

    important-winter-64905

    09/01/2021, 5:47 PM
    Cool. I appreciate the nudge. I’ll try to revisit them separately. I’ve nevertheless learned a lot by see Django specific examples which handle htmx request/response examples.
  • u

    user

    09/01/2021, 5:51 PM
    On htmx, requests always starts on HTML (AFAIK). Django HTML responses are a View thing. It's almost that simple.
1...456...100Latest