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

    hundreds-camera-24900

    03/02/2022, 2:35 PM
    Adam ended up rewriting like everything I did lol - RST not my strong suit
  • h

    hundreds-camera-24900

    03/02/2022, 2:36 PM
    I am going to put a PR in to updat ethe tips section for a second approach on CSRF handling and how I do flash messages
  • m

    mysterious-toddler-20573

    03/04/2022, 3:04 PM
    icymi: https://blog.benoitblanchon.fr/django-htmx-toasts/
  • s

    swift-belgium-99945

    03/07/2022, 10:02 AM
    Hi all, just wondering which is the best method for achieving this. Basically, I have a mini django app with a load of reports (some of which are relatively slow to run/load). So in the view for each report I'm returning a htmx template which then calls the view again upon load and showing a "loading" type image in the meantime. Presently I'm checking for the htmx request header on the server side, so if there's no header return the template, if there is then return the content. My question is: Is this the best way to do this/how does everyone manage this? It's concise I suppose having everything in one view but it breaks the browser back button unless I add a header not to cache. (Technique here: https://django-htmx.readthedocs.io/en/latest/tips.html#partial-rendering)
  • b

    blue-gold-89534

    03/07/2022, 11:22 AM
    you could try sse extensions ... https://htmx.org/attributes/hx-sse/
  • w

    white-motorcycle-95262

    03/09/2022, 2:20 AM
    @User are you using this approach now that
    hx-disinherit
    has been implemented, or are you doing something different these days? I'm thinking of implementing this now, but also adding
    hx-history-elt
    to
    #main-body-wrapper
    so that I can still load JS libs right before
    </body>
    (I recently discovered that putting scripts down there causes them to execute multiple times when using browser back, unless you change the
    hx-history-elt
    ).
  • a

    ancient-angle-7831

    03/10/2022, 7:09 AM
    Are there any examples of how to use
    afterSwap
    ?
  • u

    user

    03/14/2022, 7:34 AM
    Hello everyone, beginner here, is htmx compatible with Django 4.0.1 ? Thank you
  • b

    blue-gold-89534

    03/14/2022, 7:35 AM
    yes
  • u

    user

    03/14/2022, 7:36 AM
    thank you
  • b

    blue-gold-89534

    03/14/2022, 7:36 AM
    there is the fabulous django-htmx package by adamchainz, I suggest you take a look at it.
  • b

    blue-gold-89534

    03/14/2022, 7:37 AM
    https://github.com/adamchainz/django-htmx
  • u

    user

    03/14/2022, 7:37 AM
    nice ! I will check it out thanks again
  • b

    blue-gold-89534

    03/14/2022, 7:37 AM
    it comes with a demo project that holds a lot of valuable insight on how to use htmx with django etc ...
  • b

    blue-gold-89534

    03/14/2022, 7:38 AM
    there is an extra folder for requirements that has a django4.0 setting
  • b

    blue-gold-89534

    03/14/2022, 7:38 AM
    https://github.com/adamchainz/django-htmx/blob/main/requirements/py310-django40.txt
  • u

    user

    03/16/2022, 1:59 PM
    Hi, I'm really struggling with the concept of Out of Band swapping. Tried to look this up, but not much info or examples other than the docs (which when it comes to oob swap, I don't really understand). Basically what I have is a in-browser terminal. The
    sendcommand
    url sends and executes the command in a terminal and returns the output of that command and displays it in "log" which is just a div . What I want to do is reset the input field on submit.
    Copy code
    html
    <div id="log"></div>
    
    <form hx-post="{% url 'sendcommand' %}" hx-swap="innerHTML" hx-target="#log">
                <input type="text" id="commandinput" name="command"/>
    </form>
    Sorry if this it not the right place to ask, but this seems like something that should be pretty easy. Feel free to send me a PM
  • h

    hundreds-camera-24900

    03/16/2022, 2:32 PM
    your post is targeting #log
  • h

    hundreds-camera-24900

    03/16/2022, 2:32 PM
    so the post's return will replace log
  • h

    hundreds-camera-24900

    03/16/2022, 2:33 PM
    it sounds like you want to add
    <input type="text" name="command" id="commandinput" hx-swap-oob="true" />
    as a top level element in the response
  • h

    hundreds-camera-24900

    03/16/2022, 2:34 PM
    it would be slightly simpler though to flip the two and use log for the out of band
  • h

    hundreds-camera-24900

    03/16/2022, 2:35 PM
    Copy code
    <div id="log"></div>
    
    <form hx-post="{% url 'sendcommand' %}" hx-swap="innerHTML">
                <input type="text" id="commandinput" name="command"/>
    </form>
    
    
    response ------
    <div id="log" hw-swap-oob="true> ....</div>
    <input type="text" id="commandinput" name="command"/>
  • h

    hundreds-camera-24900

    03/16/2022, 2:35 PM
    since input is related to the form it makes sense to me for that to be the target
  • g

    gorgeous-airport-54386

    03/16/2022, 2:36 PM
    the main purpose of the request is to get the command output though
  • g

    gorgeous-airport-54386

    03/16/2022, 2:36 PM
    it seems odd
  • h

    hundreds-camera-24900

    03/16/2022, 2:36 PM
    this is an interesting question, should target response be the purpose of the request or the one pertaining to the structure of the triggerer
  • h

    hundreds-camera-24900

    03/16/2022, 2:37 PM
    to me it feels like the triggerer, because then it's generalizeable to different purposes
  • h

    hundreds-camera-24900

    03/16/2022, 2:37 PM
    but of course you could claim the inverse too, and say "I want different ways to update the log"
  • g

    gorgeous-airport-54386

    03/16/2022, 3:11 PM
    i mean, i would use javascript to clear the input here
  • b

    brave-magazine-28098

    03/16/2022, 10:19 PM
    This is interesting. Django + React as the template engine: https://www.reactivated.io/
1...545556...100Latest