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

    mysterious-toddler-20573

    07/24/2022, 2:00 PM
    yes, but you'll need the correct css selector:
    Copy code
    [name='element'],[name='element2']
  • m

    mysterious-toddler-20573

    07/24/2022, 2:00 PM
    I often find its easier to introduce a class to all the stuff I want to include if they are scattered around
  • m

    mysterious-toddler-20573

    07/24/2022, 2:00 PM
    and just use that class
  • c

    calm-queen-64495

    07/25/2022, 10:27 AM
    How do you do a hx-trigger on a date field hx-trigger="keyup changed"?
  • c

    calm-queen-64495

    07/25/2022, 10:28 AM
    I can only get the trigger to work on a clicked date field
  • c

    calm-queen-64495

    07/25/2022, 10:53 AM
    This only works once I select the date click out of the date and then click it again
  • m

    mysterious-toddler-20573

    07/25/2022, 3:21 PM
    use
    monitorEvents
    in chrome to see what events are being triggered on the input and see if there are any good options: https://htmx.org/docs/#debugging
  • a

    astonishing-kilobyte-60820

    07/27/2022, 12:14 PM
    I am running into a strange issue with
    hx-swap-oob
    . I have this
    Copy code
    html
     <tr><td><button hx-post="/" hx-target="closest tr" hx-swap="outerHTML"></button></td></tr>
    
    <!-- my response -->
    <tr>.....</tr>
    That works fine. But when my response is this, the weirdest thing happens.
    Copy code
    html
       <div id="messages" hx-swap-oob="true">....</div>
       <tr>....</tr>
    When I do that, the message works but all the html tags get stripped out of my
    <tr>
    so instead I just get whatever text was in the
    tr
    but all
    tr
    tags and
    td
    tags are left out of the response. Any ideas?
  • m

    mysterious-toddler-20573

    07/27/2022, 1:17 PM
    Yeah, this is a problem with parsing table rows in the older manner. You can turn on template-based parsing and that will probably fix it, https://htmx.org/docs/#config
  • m

    mysterious-toddler-20573

    07/27/2022, 1:17 PM
    set htmx.config.useTemplateFragments to true and it should work
  • a

    astonishing-kilobyte-60820

    07/27/2022, 10:59 PM
    I already have that set in the head like this, and it's still not working. Any other ideas?
    Copy code
    html
        <meta name="htmx-config" content='{"useTemplateFragments":true}'>
  • h

    hallowed-architect-39752

    07/30/2022, 11:12 PM
    I learned about template context processors, and wrote one which passes a
    base_template
    . Its value depends on whether or not the request was used with htmx or not, as per the tip on https://django-htmx.readthedocs.io/en/latest/tips.html.
    Copy code
    python
    def htmx_base_template(request):
        if request.htmx and not request.htmx.boosted:
            base_template = "partial.html"
        else:
            base_template = "base.html"
    
        return {
            "base_template": base_template,
        }
  • h

    hallowed-architect-39752

    07/30/2022, 11:13 PM
    now I don't have to write it anytime I want to do htmx base template stuff
  • a

    aloof-crayon-56651

    08/02/2022, 2:30 AM
    I have a contact form that isn't working, but it isn't sending me to the debug page (Django). Using htmx.logAll() in console, I see the serverResponse has the debug page. How do I redirect to it when I get an error?
  • e

    early-camera-41285

    08/02/2022, 10:21 AM
    If the debug page is a response to an HTMX Ajax request, then can't you see it in the browser developer tools > Network?
  • a

    aloof-crayon-56651

    08/02/2022, 10:39 AM
    I'm not at my computer now (nearly bedtime here), but I'll check it out tomorrow. For the record, it's my first time putting a Django page in public. Learned that I needed to add a default email address to send messages from, as well as a email address for error logs, in the settings. I think I needed to add my email host to ALLOWED_HOSTS. Looking at logs gave nearly no help ("connection refused").
  • m

    mysterious-toddler-20573

    08/04/2022, 3:33 AM

    https://www.youtube.com/watch?v=lWdzCUxsMNcâ–¾

  • i

    incalculable-holiday-29658

    08/04/2022, 7:05 AM
    does htmx custom-event works on redirect?
  • r

    red-france-69804

    08/04/2022, 2:30 PM
    Hi there! Does anyone know how to combine a
    ListView
    and a
    DeleteView
    in Django ? With HTMX, it would be useful to me, to be able to not just remove the deleted object in the list (like in the examples), but to update the DOM with the new table. I explained my issue here in detail here: https://stackoverflow.com/questions/73237624/django-combine-listview-and-deleteview-to-use-with-htmx
  • b

    blue-ghost-19146

    08/04/2022, 2:52 PM
    I'd suggest adding an
    HX-Trigger
    response header (https://htmx.org/headers/hx-trigger/) to your
    DeleteView
    and listening for it on the list (
    hx-trigger="myCustomEvent from:body"
    ) along with the other
    hx-
    attributes required for calling your ListView and thus refreshing the fragment. That's what I do and it seems to work pretty well.
  • h

    hundreds-camera-24900

    08/04/2022, 3:58 PM
    Should be able to override the list view's delete method handling and then use hx-delete to trigger it
  • h

    hundreds-camera-24900

    08/04/2022, 3:58 PM
    I think I've generally used two endpoints for that case
  • h

    hundreds-camera-24900

    08/04/2022, 3:59 PM
    nope, nm overrode the delete method: https://github.com/gone/animelister/blob/master/animelister/home/views.py#L148-L160
  • r

    red-france-69804

    08/04/2022, 4:26 PM
    Thanks ! I'll take a look to do something similar. As the need could occur for DeleteView, CreateView, or UpdateView, I guess the best would be to create a mixin which returns the result list, rather than the item itself
  • h

    hundreds-camera-24900

    08/04/2022, 6:15 PM
    on the stuff I'm doing now
  • h

    hundreds-camera-24900

    08/04/2022, 6:15 PM
    I'm finding a pattern i use often is:
  • h

    hundreds-camera-24900

    08/04/2022, 6:15 PM
    / which loads with a section like
  • h

    hundreds-camera-24900

    08/04/2022, 6:15 PM
    Copy code
    html
      <div class="flex flex-col"
        hx-trigger="load"
        hx-get="{% url "appointment-list" %}"
        hx-target="#appointment-left-content"
        hx-swap="innerHTML">
        loading appointments..
        <img class="self-center"
          height="100"
          width="100"
          src="{% static "img/loading.svg" %}">
      </div>
  • h

    hundreds-camera-24900

    08/04/2022, 6:16 PM
    and then the page loads, hx-trigger fires and the data is lazy loaded in
  • h

    hundreds-camera-24900

    08/04/2022, 6:16 PM
    and then you have appointment-list and there's a couple contexts that can be used in
1...676869...100Latest