https://htmx.org logo
Join Discord
Powered by
# šŸ”„-django-htmx
  • b

    big-engine-22348

    10/21/2022, 5:39 PM
    Thanks, I take a look at it tomorrow. TBH i dont want my code to messy. Already having django/htmx/ some extra JavaScript and so one... i don't like to dependent on too many 3. party things.
  • b

    big-engine-22348

    10/21/2022, 5:40 PM
    my idea was an "hx-focus" attribute that could maybe handle this. This could be very usefull in many of my projects.
  • b

    big-engine-22348

    10/21/2022, 5:41 PM
    Not only retarget the same elements with htmx but guide the user from different inputs would be very helpful i think
  • m

    mysterious-toddler-20573

    10/21/2022, 5:55 PM
    If you include autofocus in the new content it should act like you say
  • b

    big-engine-22348

    10/21/2022, 6:10 PM
    yeah but i can't. The partial is a template loop form django and generates from the user input new forms. In this case i cant split the template or the loop. But i don't want to "cry to loud" maybe this is a less common case than i thought. I try tomorrow if i find some half clean way to do it. Anyway still love your work šŸ™
  • l

    little-advantage-56932

    10/21/2022, 6:32 PM
    Hi everyone. I’m trying to create an SPA in Django with HTMX. I’m trying to push a song url to a HTML audio element. How would I do that?
  • m

    mammoth-family-48524

    10/22/2022, 9:10 AM
    What code do you have so far?
  • i

    icy-analyst-57034

    10/24/2022, 9:39 AM
    I think you can solve this with Django. Something like within your forloop
    {% if forloop.first %} autofocus{% endif %}
    or whatever other condition you pass in your context to know when field to focus on
  • b

    breezy-minister-64652

    10/24/2022, 10:00 AM
    Would it be bad practice to not use hx-put or hx-patch to edit a field, but hx-post instead ?
  • b

    breezy-minister-64652

    10/24/2022, 10:00 AM
    I kinda do everything using post requests, even to delete
  • b

    breezy-minister-64652

    10/24/2022, 10:02 AM
    Is there any drawback to it except maybe taking a bit more time to code ? For example, I already did a view to delete an element using a POST request, which works really fine. But would there be any benefit in making it a DELETE request ? Especially using HTMX ?
  • t

    tall-dinner-62086

    10/24/2022, 10:03 AM
    For one, you wouldn't be violating the HTTP specification
  • t

    tall-dinner-62086

    10/24/2022, 10:04 AM
    Hippies will tell you methods don't matter. These people are wrong and should be made to see reason.
  • t

    tall-dinner-62086

    10/24/2022, 10:04 AM
    Sure, it works. It would also work if you made everything a GET request
  • t

    tall-dinner-62086

    10/24/2022, 10:05 AM
    Just like creating things with a DELETE request would work. Your server does what you tell it to regardless of what the message actually is. If you post to
    /users
    your server could just create a new entry on the
    orders
    table. But that's not really what any reasonable person would expect.
  • b

    breezy-minister-64652

    10/24/2022, 10:07 AM
    Is it just for "readability" that these method's names exist then ?
  • b

    breezy-minister-64652

    10/24/2022, 10:08 AM
    Then I could technically just take the POST request I wrote in that example, rename the method to DELETE, and it would still be a valid way to code ?
  • t

    tall-dinner-62086

    10/24/2022, 10:13 AM
    They exist so everyone knows what to expect when they see a method name. You don't expect a GET to have a body, you don't expect a PUT to delete a record, you don't expect a DELETE to do anything other than delete.
  • t

    tall-dinner-62086

    10/24/2022, 10:13 AM
    "a valid way to code" would be to just use the right methods from the start
  • b

    breezy-minister-64652

    10/24/2022, 10:15 AM
    Alright, thank you for your input!
  • h

    hundreds-camera-24900

    10/24/2022, 4:09 PM
    https://github.com/jazzband/django-debug-toolbar/pull/1686/files šŸŽ‰
  • h

    hundreds-camera-24900

    10/24/2022, 4:09 PM
    once this releases this + the update on ajax feature we landed a few months ago means htmx and djdt should be 100% compatible
  • b

    blue-gold-89534

    10/26/2022, 1:49 PM
    I tried to create an indication for starting downloads:
    Copy code
    python
    def start_dl(request, pk):
      o = Model.objects.get(pk = pk)
      try:
        return FileResponse(open(o.file), 'rb'), as_attachment = True)
      except Model.DoesNotExist:
        m = f"""<img src="{static('images/alert.svg')}" hx-swap-oob="true" hx-targt="download-{o.pk}"> """
        return HttpResponse(format_html(m))
    Copy code
    html
    <a href="{% url 'download' something.pk %}">
      <img src="{% static 'images/dl.svg' %}" id="download-{{object.pk}}">Download
    </a>
    Everything works so far but after a click on Download I always get a new site instead of only the new icon in place? Is it, because I am not using an hx-get but a d
  • r

    red-france-69804

    10/26/2022, 2:22 PM
    Hi guys. I built a toast system with HTMX, using https://htmx.org/headers/hx-trigger/ to trigger a client side event. It works as expected with HTMX. However, what if I want to use this toast system for "normal" Django views that do not use HTMX at all? Is there a way to tell Django to fire an event if it finds an "HX-Trigger" header (or another) in the response, outside of htmx? Thanks!
  • g

    green-activity-6102

    10/26/2022, 3:45 PM
    yes, thats just a regular hyperlink
  • b

    blue-gold-89534

    10/26/2022, 6:06 PM
    how could I achieve that? Serving the answer with an autostart JS download? I want to avoid JS as much as I can
  • g

    green-activity-6102

    10/26/2022, 7:58 PM
    i dont think HTMX currently has a mechanism for handling file downloads
  • g

    green-activity-6102

    10/26/2022, 7:59 PM
    https://discord.com/channels/725789699527933952/725789747212976259/1017134686776086665
  • r

    red-france-69804

    10/27/2022, 8:01 AM
    Hi guys, beginner question here šŸ‘¶ 
 I'm trying to figure how to replace this usual Django workflow with HTMX: > The user go to "New item" page to create it. Then, when the object is actually created, the user is redirected to the "Detail item" page of that item.
 Of course, with HTMX I want to avoid any HTTP redirection and just reload the minimal amount on data.

 Let say you have 2 views:
    CreateItemView
    and
    DetailItemView
    . At the end of the
    CreateItemView
    , how do you manage to use the
    DetailItemView
    , without a redirect? 

 This seems to be a very common need, so I guess the pattern is well known. 
 Thank you!
  • f

    few-vegetable-15970

    10/27/2022, 11:03 AM
    You would have to make an implement CreateItemView.form_valid which renders the template of DetailItemView or the inner part of it
1...798081...100Latest