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

    melodic-advantage-28381

    11/09/2022, 12:13 PM
    How about using response header
    Hx-Retarget
    in order to override
    hx-target
    on some specific cases, like when there's an error? https://htmx.org/reference/#response_headers
  • f

    fancy-elephant-10660

    11/09/2022, 12:20 PM
    oh my I didn't see that one. So then still its a only a little bit more easy to use hx-trigger="reload from:body" as this is less code... Thx
  • f

    fancy-elephant-10660

    11/09/2022, 12:30 PM
    How would you do a retarget and reswap with django-htmx ?
  • m

    melodic-advantage-28381

    11/09/2022, 1:40 PM
    django-htmx doesn't provide any sugar for
    Hx-Retarget
    or
    Hx-Reswap
    AFAIK. But it's as easy as adding a custom HTTP header to a Django HTTP Response (https://docs.djangoproject.com/en/4.1/ref/request-response/#setting-header-fields)
  • b

    blue-gold-89534

    11/09/2022, 11:12 PM
    i just re-read that - this is actually not correct. I put it in the HTML I return from the hx-get. How would you suggest I do it?
  • b

    bitter-monkey-50309

    11/09/2022, 11:25 PM
    You'll have to return the response object yourself with the header set, check the link David's just posted
    b
    • 2
    • 4
  • r

    rhythmic-dentist-61727

    11/11/2022, 7:04 AM
    Is there a beginner's tutorial for htmx with Django? I can get the simple Click me button working with Django (3.2) but not the Active search querying the database. It isn't even calling the view. Thanks for any pointers.
  • r

    refined-waiter-90422

    11/11/2022, 8:04 AM
    might give you some ideas.
  • r

    refined-waiter-90422

    11/11/2022, 8:05 AM
    common patterns guide.
  • b

    blue-gold-89534

    11/11/2022, 3:13 PM
    You ll have to return the response
  • w

    white-motorcycle-95262

    11/11/2022, 10:57 PM
    I know this isn't really HTMX based, but this is the best community I've found for asking questions like this: I've decided that some 3rd-party APIs I use are taking too long to respond, making the request-response cycle for my own website too lengthy (e.g., a button that adds someone to a ConstantContact email list.. I get the request, fire off a payload to the ConstantContact API, which takes too long, and then send response to the user). I don't think I want anything as heavy-weight or full-featured as celery, but I just have a handful of instances where I want to return a response and then process some code. Any suggestions for what I should look into?
  • s

    shy-zebra-22292

    11/13/2022, 12:07 PM
    there is a whole playlist on youtube https://m.youtube.com/playlist?list=PL-2EBeDYMIbRByZ8GXhcnQSuv2dog4JxY
  • s

    shy-zebra-22292

    11/13/2022, 12:08 PM
    if you share the code that is not working maybe someone can help...
  • w

    witty-daybreak-45092

    11/14/2022, 6:57 PM
    Hi, all! I have a deployed Django site running htmx and have an issue where the back button after reloading the same page will result in an empty page. Details in thread.
    m
    m
    • 3
    • 42
  • m

    mammoth-family-48524

    11/18/2022, 4:11 AM
    On some occasions, when the client sends a hx-delete request, Django responds with a full 403 error page (‘raise PermissionDenied’). HTMX doesn’t do anything with that response by default. Is there a way to have HTMX display the 403 page? Swap the body perhaps?
  • s

    shy-zebra-22292

    11/18/2022, 6:43 AM
    Hello guys, I have been wondering and looking around for examples... what is the best way to handle for validation of complex forms in Django+htmx? By "complex" i mean where for example the same form validates username length, username not in db, and profile picture (file uploaded in the same form) should not exceed say 5 MB and 4k resolution. There are some methods I have been thinking of to validate this form but I'd love to hear your ideas. (Please point to any relevant examples/tutorials if any/demos/production projects too.)
  • m

    mammoth-family-48524

    11/18/2022, 8:23 AM
    I think it’s the same as non-HTMX. You submit the form, validate it, and if it has errors, you return the form with errors included. Using HTMX means, when you do that, you can just return the form html (not the whole page) and update the dom directly - which means the user sees the page update without waiting for a page reload
  • s

    shy-zebra-22292

    11/18/2022, 1:10 PM
    yeah.. that us the obvious pattern.. but i was thinking about more fine grained checks.. e.g. "check only the 'email' field for errors (on change) by hitting something like /register/email/some@email.com" i can see it done but it will result in a ton of code.. also.. if fields are interdependent (say we need to check password is the same) htmx requests dont seem to cut it. Maybe a little js is better here.
  • m

    mammoth-family-48524

    11/18/2022, 2:33 PM
    Ahh I see. I use one of two ways to do that 1. make extra forms for the little onchange etc requests I want to do. Eg a form with just an email field in it. Or a form with just the two passwords in it. Or 2. If I’m updating a model object, I like to use hx-patch, and in the view I test if it’s a patch request, and if it is, I get the model object’s data as a dict and merge that with the data in the hx-patch request, create a model form instance using that, validate etc, and then respond with what makes sense. I can paste some code when I’m back at my pc if that helps
  • m

    mammoth-family-48524

    11/18/2022, 2:42 PM
    It all works pretty well in terms of the view and form, but the templates are pretty annoying - I have lots of templates that I {% include %} into the main ones, or include templates within templates - so I can choose to return part of the page - but it gets a bit confusing trying to remember where the bit of html I want to change is. I really want to be able to use something like a css selector to grab just a bit of a large template and send that back. I haven’t tried making a function to do that yet though.
  • m

    mysterious-toddler-20573

    11/18/2022, 2:47 PM
    https://pypi.org/project/django-render-block/ ?
  • f

    flaky-fish-46395

    11/18/2022, 3:51 PM
    Hi guys, i wanna make chained dropdown with 3+ elements with python, django and htmx without javascript, like 'city' -> 'town' -> 'street'. Well actually i did that, but when i pick the 'street' and then change the 'city' only 'city' and 'town' change. if i want to change the 'street' i have to change the 'town' or it will stay the same. I kinda understand why, cus 'city' triggers get request to the 'town' on change and 'town' triggers request to the 'street'. But i want it to work like if i change the 'town' every field should go to default and if i change 'town' then 'street' should go to default. Do you guys know how to connect those fields properly or maybe can recommend a good tutorial?
  • h

    hundreds-camera-24900

    11/18/2022, 4:34 PM
    I think django htmx does that for you through a script
  • h

    hundreds-camera-24900

    11/18/2022, 4:34 PM
    https://django-htmx.readthedocs.io/en/latest/extension_script.html
  • m

    mammoth-family-48524

    11/18/2022, 8:59 PM
    That looks good! 🥳
  • m

    mammoth-family-48524

    11/18/2022, 9:04 PM
    Thanks! It doesn’t look like it does it (it’s just for debug) but it shows me how 🥳. Why doesn’t HTMX do it by default?
  • h

    hundreds-camera-24900

    11/18/2022, 9:05 PM
    I meant to send that to your 403 comment
  • h

    hundreds-camera-24900

    11/18/2022, 9:05 PM
    whoops sorry
  • h

    hundreds-camera-24900

    11/18/2022, 9:06 PM
    well I think it doesn't because it's not 100% clear what it should do by default
  • h

    hundreds-camera-24900

    11/18/2022, 9:06 PM
    often 403 errors are handled at the application level and not shown to users
1...828384...100Latest