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

    clean-vegetable-65167

    07/15/2021, 2:08 PM
    wow great, that's exactly what I need, thank you
  • s

    salmon-xylophone-28580

    07/15/2021, 3:32 PM
    But this browser full page reload is what you don't want in the long run. You want to update only a snippet, otherwise it makes not much sense to use htmx. And then you might realize that several function-base-view methods are simpler than one CBV.
  • c

    clean-vegetable-65167

    07/15/2021, 3:33 PM
    yeah I know but it is not often, htmx gives me nice backend validation and after success I get full page reload where on several places are edited data counted or displayed in some way, which would be difficult to all update
  • b

    bored-napkin-20287

    07/16/2021, 6:22 AM
    Nice! Also using Django + htmx (well hyperscript...) in my latest project. 👋
  • e

    elegant-london-97728

    07/16/2021, 7:14 AM
    Welcome to the new and expanding club!
  • s

    salmon-xylophone-28580

    07/16/2021, 8:43 AM
    BTW, if you have question, then please create a question at Stackoverflow, and then copy+paste the link here (or htmx-general). This helps other people to find the right answer. Thank you. Don't be shy, start asking!
  • a

    astonishing-fish-5228

    07/19/2021, 10:05 PM
    hello, quick question, can you add DRF on top of django + htmx ? for an native app
  • u

    user

    07/19/2021, 10:16 PM
    @User sure! You have to architect your Django app with URLs segregated for API calls and Web calls or work with content-types to choose the right response format.
  • a

    astonishing-fish-5228

    07/19/2021, 10:18 PM
    great i think im going to like htmx
  • s

    salmon-xylophone-28580

    07/20/2021, 7:17 AM
    How do you integrate the htmx JS files into your Django application? Up to now I have not found the perfect way yet. I started to create a list with the different ways how you could get the JS files into you app. Feedback is welcome: https://github.com/guettli/django-and-npm
  • b

    blue-manchester-57655

    07/21/2021, 12:27 AM
    After Reading Luke Plant's article
    Django Views — The Right Way
    (https://spookylukey.github.io/django-views-the-right-way/), I stick with FBVs for the most part, and have refactored several CBVs to FBV as well. In the end, I find them much more usable and explicit. There's less thought involved when reading my FBV code later. I don't have to ask questions about whether a method is overriding another, the order of logic flow, etc.
  • b

    blue-manchester-57655

    07/21/2021, 12:30 AM
    I just use CDN in my base template and call it a day. If I can avoid using NPM in my django projects until I die, it will be too soon 🤣
  • u

    user

    07/21/2021, 5:27 PM
    I don't know if it was already posted here: https://go.jetbrains.com/dc/oZkb5IUc2Y-gs3UFyHbi_1phWa97_rOKz04iYi4uVPawp6D5r6wHH53b8qZY1R5wFe1I8vT4eq7WFiteZ6_ceLPzB2AEQg-l4FXMQDNLKZ_oBczGc-4OKFidIi7FDAjYSs3znSR2q8_dOzY8J5LKRcBGZ7Od1DKery4ovbElHqKCYM6pOq0R2DLH9VQl6f8N/NDI2LVFWRC0xMTQAAAF-aMMiAp5rS8NJDqAFm42juo1_o6uhPBnfNo252efGWBkVn96flUfvGxlmGJPN2mIp1OLFcAE=
  • s

    swift-arm-37963

    07/22/2021, 5:51 AM
    hi all! can anyone help me with this issue that I'm facing ? Basically I want to remove the parent div of a form on a successful DeleteView call. Here's how I made it to be
    Copy code
    <form
                            method="post"
                            action="{% url 'requests:attachment-delete' object.uuid attachment.uuid %}"
                            hx-confirm="Are you sure?"
                            hx-target="closest div"
                            hx-swap="outerHTML"
                        >
                            {% csrf_token %}
                            <button type="submit" class="btn-close" aria-label="Close"></button>
                        </form>
    but it does not do anything at the moment.
  • s

    swift-arm-37963

    07/22/2021, 5:56 AM
    here's my view. I've overriden the delete method to return no response instead of redirecting to a success_url
    Copy code
    @transaction.atomic
        def delete(self, request, *args, **kwargs):
            self.object = self.get_object()
            self.object.delete()
            messages.add_message(self.request, messages.SUCCESS, 'Successfully deleted request!')
            return HttpResponse(status=204)
  • s

    swift-arm-37963

    07/22/2021, 5:56 AM
    thanks!
  • u

    user

    07/22/2021, 10:51 AM
    My guess, without looking at the htmx code, is that you should return an empty
    <div>
    instead of the
    204
    response.
  • m

    mysterious-toddler-20573

    07/22/2021, 1:33 PM
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204
  • m

    mysterious-toddler-20573

    07/22/2021, 1:33 PM
    > The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.
  • m

    mysterious-toddler-20573

    07/22/2021, 1:33 PM
    You want a 200 w/ empty content in this case
  • p

    plain-kangaroo-26043

    07/22/2021, 7:24 PM
    I have alpine and some custom JS as well as htmx in my project, so I package all the JS up with esbuild. Other than whitenoise /collectstatic I tend to keep the JS and Django separate.
  • s

    salmon-xylophone-28580

    07/23/2021, 7:05 AM
    Thank you for reply. I am unsure if I need a tool like esbuild. I created a package.json file and run
    npm install
    . Now I have the libraries which I want (for example htmx.min.js) and can use them via staticfile+whitenoise. Up to now I have no build step. Or is there a useful feature which I miss, if I don't use esbuild?
  • c

    cold-morning-35868

    07/23/2021, 9:33 AM
    Didn't know about that guide but that's gold! Thanks for sharing it here 🙂
  • p

    plain-kangaroo-26043

    07/23/2021, 6:32 PM
    I already had a build setup for Tailwind so wasn't a big deal to add esbuild - it was simpler than dealing with the complexities of webpack. If you don't have much custom JS though using html.min.js as-is or a CDN is fine.
  • v

    victorious-room-74725

    07/30/2021, 4:48 PM
    Thank you for this. I have been spending the past month or two dealing with CBV's and their unintuitive nature.
  • i

    incalculable-scientist-18707

    07/31/2021, 3:51 PM
    Anybody know if htmx will work with two submit buttons on a form. Having trouble getting the "name" and/or "value" submit button attributes out of request.POST in the view.
  • v

    victorious-room-74725

    07/31/2021, 3:53 PM
    Does this not work? https://stackoverflow.com/questions/21505255/identify-which-submit-button-was-clicked-in-django-form-submit
  • i

    incalculable-scientist-18707

    07/31/2021, 3:59 PM
    Correct . That does not work for some reason. Works in a non-htmx version with a CBV.
  • m

    mysterious-toddler-20573

    07/31/2021, 4:04 PM
    are you using the latest version of htmx? We changed it to include the clicked button values.
  • m

    mysterious-toddler-20573

    07/31/2021, 4:04 PM
    Also note that you can put the
    hx-post
    directly on one of the buttons and include a value w/
    hx-vals
    as a fall back
12345...100Latest