https://htmx.org logo
Join Discord
Powered by
# 🔥-django-htmx
  • i

    incalculable-scientist-18707

    07/31/2021, 4:28 PM
    Thanks!! I'm on 1.4.1...looks like I need to update to 1.5.0. I will also try the hx-vals if that doesn't work.
  • i

    incalculable-scientist-18707

    07/31/2021, 5:51 PM
    BTW...upgrading worked.
  • v

    victorious-room-74725

    08/01/2021, 1:51 AM
    So I'm planning to rewrite my site to use HTMX instead. I'm struggling to get a form to post / get swapped. I'm getting [HTTP/1.1 500 Internal Server Error 31ms]
  • v

    victorious-room-74725

    08/01/2021, 1:51 AM
    Oh nvm. I found out how to see more detailed error message 😄
  • v

    victorious-room-74725

    08/01/2021, 5:09 PM
    I had totally misunderstood how npm and django applications needed to work together. Don't try and automatically bridge the npm and the django. Create a minified js file from the npm project and just serve that min js file in static and call it a day. In the case of htmx, you can just download htmx.min.js and save as a text file to serve from static directory.
  • u

    user

    08/02/2021, 4:51 PM
    Hey all, I recently wrote this little bit of code to build on the django-htmx package: https://github.com/Tiny-Tiny-App/django-htmx-extras
  • u

    user

    08/02/2021, 4:52 PM
    Its basically a set of HTMX aware class based views. All thanks to a modified version of the
    TemplateResponseMixin
  • b

    blue-manchester-57655

    08/02/2021, 4:58 PM
    Good stuff. Have you considered asking if this could be rolled into dgango-htmx itself rather than as a separate package? (I'm so exhausted with maintaining a million dependencies 😆)
  • u

    user

    08/02/2021, 5:00 PM
    Yes I did before splitting the code into its own. The maintainer mentioned this was out of the scope of his goal with the project and he didn’t like default Django class based views. Which is is totally fine. I wouldn’t want to add cruft to such a lean project.
  • u

    user

    08/02/2021, 5:01 PM
    Plans are to keep it up to date with releases. Though it shouldn’t change much given how this I just a play on class based views and the core of the Django htmx library
  • u

    user

    08/02/2021, 5:01 PM
    Should be on pypi soon.
  • u

    user

    08/02/2021, 5:02 PM
    Thanks for asking
  • s

    stocky-sundown-96428

    08/03/2021, 4:26 PM
    Has anyone tried to mix django-filter and htmx? Looking for examples 👀 I got it working using a CBV inheriting
    FilterView
    and hx-get 🎉 I set
    hx-trigger="change"
    but apparently forcing a
    onchange="this.form.submit()"
    directly on an input bypasses htmx... I'm also trying to catch the change event from a flatpickr input. No luck yet.
  • m

    mysterious-toddler-20573

    08/03/2021, 4:28 PM
    if you are struggling with events, there is a nice tool in chrome, `monitorEvents`: https://htmx.org/docs/#debugging
  • s

    stocky-sundown-96428

    08/03/2021, 6:11 PM
    Thanks, that's a start
  • v

    victorious-room-74725

    08/03/2021, 9:15 PM
    Is it possible to have an hx-post event conditionally redirect the full page from the view?
  • v

    victorious-room-74725

    08/03/2021, 9:15 PM
    I was thinking if x, then httpresponse, else, httpresponseredirect
  • m

    mysterious-toddler-20573

    08/03/2021, 9:20 PM
    you can use a client-side redirect if you want the browser side to do it, otherwise you can do a full regular redirect and then do an OOB swap with the body
  • v

    victorious-room-74725

    08/03/2021, 9:29 PM
    Hmm. I did some testing and it seems like htmx doesn't care if you're sending httpResponse vs httpResponseRedirect. So I may need to just also implement the if / then logic on the front end
  • c

    cold-morning-35868

    08/04/2021, 7:11 AM
    Could you do a client-side redirect initiated by sending
    HX-Redirect
    header in the server response? eg.
    Copy code
    return HttpResponse(headers={'HX-Redirect': url})
    ( https://htmx.org/reference/#response_headers )
  • v

    victorious-room-74725

    08/04/2021, 1:52 PM
    Thanks, I'll have to try this out \:D
  • u

    user

    08/04/2021, 2:07 PM
    Maybe post some code?
  • v

    victorious-room-74725

    08/05/2021, 1:26 AM
    Okay, it looks like, my current version at least doesn't like headers as an argument there. What seems to work is response = HttpResponse('Text') response['HX-Redirect'] = url
  • v

    victorious-room-74725

    08/05/2021, 1:26 AM
    return response
  • v

    victorious-room-74725

    08/05/2021, 1:30 AM
    I think that the relative url is maybe insufficient.
  • v

    victorious-room-74725

    08/05/2021, 1:41 AM
    I'm missing something :/ I hacked in the full, working url and it didn't work
  • i

    incalculable-scientist-18707

    08/05/2021, 1:42 AM
    New question: I'm trying to allow more navigation with my htmx views. hx-push-url="true" works for navigating back and forth, but when I click refresh, it reloads just my partial, which does not have the base template. Should I add an if statement to show my base template if there is a reload??? Not sure that's feasible. Any suggestions?
  • v

    victorious-room-74725

    08/05/2021, 1:49 AM
    Okay- I figured it out \:D I forgot to update this form in my template to use hx-post !
  • m

    mysterious-toddler-20573

    08/05/2021, 5:25 AM
    The right thing is to check for the
    HX-Request
    header. If is is present, render the partial, if not, render the entire page
  • u

    user

    08/05/2021, 8:55 AM
    Hey, I am trying HTMX for the first time. I am searching for a way to integrate HTMX into my Django Bootstrap4 select field. I need a search field inside. Any idea? Is this the right way to do? 🙂
12345...100Latest