https://htmx.org logo
Join Discord
Powered by
# πŸ”₯-django-htmx
  • g

    glamorous-teacher-52191

    01/26/2022, 3:04 PM
    I was checking out this example on
    inline validation
    https://htmx.org/examples/inline-validation/ - and was wondering if anyone had success with
    file
    type inputs? My case is that I'd like to do some validation as soon as a file is added to a file field, before submitting the form, but it seems the POST request acts a bit differently, and I'm not sure how to handle on the Django side. If I were to submit the form normally, the contents of
    request.FILES
    would contain a
    InMemoryUploadedFile
    that could be processed by Django, but with a POST on the field change itself, the
    request.FILES
    dict is empty, and instead there's a
    [object File]
    in
    request.POST
    , which seems to just be a string. Any help or pointers would be appreciated πŸ™‚
  • p

    plain-kangaroo-26043

    01/26/2022, 7:00 PM
    Maybe set hx-encoding? https://htmx.org/attributes/hx-encoding/
  • g

    glamorous-teacher-52191

    01/26/2022, 7:05 PM
    That did the trick! Makes complete sense. Thanks a ton! πŸ™‚
  • b

    brave-magazine-28098

    01/27/2022, 3:01 AM
    has anyone used https://mitchel.me/slippers/docs/introduction/ ? I'm looking for a bit more robust component system. It doesn't appear to support multiple children slots though for passing html.
  • b

    bland-coat-6833

    01/27/2022, 9:21 AM
    I think @User has. At least that's what search suggests.
  • p

    plain-kangaroo-26043

    01/27/2022, 1:49 PM
    I've been planning to play around with it in a suitable project: I have been doing a lot with Tailwind recently and have been looking for a decent Django template-based component system, as Tailwind works best with a component library.
  • p

    plain-kangaroo-26043

    01/27/2022, 1:51 PM
    also it doesn't appear to have good integration with Django forms?
  • p

    plain-kangaroo-26043

    01/27/2022, 2:28 PM
    (although there's crispy or widget tweaks so that's probably not a showstopper)
  • h

    hundreds-camera-24900

    01/27/2022, 3:00 PM
    yeah my opinion is that django-components are more powerful and slippers has better template syntax
  • b

    brave-magazine-28098

    01/27/2022, 7:50 PM
    Ah nice - django-components looks like exactly what I am looking for with "slots". Thanks πŸ™‚
  • p

    plain-kangaroo-26043

    01/27/2022, 8:33 PM
    I wonder though if I really want a more component-based model maybe Jinja2 + macros are a better fit
  • b

    bland-coat-6833

    01/27/2022, 9:18 PM
    I'm playing with Starlette and Jinja2 and it's going well. Just about to try a couple of macros. (once I get SAML auth sorted πŸ™„ )
  • c

    careful-room-54859

    01/28/2022, 1:56 AM
    Has anyone worked with Jinja2 + WTForms to create a multi select element?
  • e

    eager-tiger-27508

    01/28/2022, 3:30 AM
    Hello I’m working on an example Haskell + htmx app and was wondering what the Django + htmx developers do for authentication. Does htmx and the HATEOAS architecture affect how you approach user authentication in your apps? Do you use JWTs or cookies or both?
  • b

    brave-magazine-28098

    01/28/2022, 7:35 AM
    Django has built in authentication that uses session cookies . Htmx doesn’t affect that in any way. It’s one of the nice things about Django - auth β€œjust works” out of the box.
  • a

    acoustic-lawyer-26558

    01/30/2022, 8:48 PM
    i'm having a weird issue with a page. as soon as a add a test between .. htmx will no longer fire
  • m

    mysterious-toddler-20573

    01/30/2022, 8:59 PM
    anything in the console?
  • a

    acoustic-lawyer-26558

    01/30/2022, 9:33 PM
    nothing in the console. if i remove hello i get expected behavior
  • m

    most-electrician-29577

    01/31/2022, 11:45 PM
    hi kind of noob question but I'm using hx-get="" to get refresh the current page which is a table displaying items in my db & I have a {% extends %} at the top which extends a navbar, which means it's loading two navbars now as my htmx method is in my {% block content %}, any help appreciated.
  • b

    bland-coat-6833

    01/31/2022, 11:54 PM
    Wrap your
    extends
    in a test for
    request.htmx
    in your template (assuming you're using the
    django-htmx
    library).
  • b

    bland-coat-6833

    01/31/2022, 11:55 PM
    That'll mean that an htmx request won't extend the template, so you won't then return the navbar, and you should just get the content you want
  • m

    most-electrician-29577

    02/01/2022, 12:03 AM
    how do i wrap in test?
  • b

    bland-coat-6833

    02/01/2022, 12:26 AM
    {% if request.htmx %}{% extends '…' %}{% endif %}
  • m

    most-electrician-29577

    02/01/2022, 12:40 AM
    Cheers! wasn't able to use extend but just used include
  • a

    ancient-rose-1570

    02/01/2022, 9:24 AM
    Hi all, novice question here, I am loading a template fragment this way:
    Copy code
    <div hx-get="{% url "deals:deal-create" listing.slug %}" hx-trigger="load" id="htmx-ref">
      {% include "includes/loading.html" %}
    </div>
    if the view at that url returns 403 I see the loading part. Is there a better way to handle loading state?
  • b

    bland-coat-6833

    02/01/2022, 10:03 AM
    So you're loading a template which displays
    loading.html
    while you do a
    GET
    to
    deals:deal-create
    . If you get a 403 then you want to replace loading... with an error or some such?
  • a

    ancient-rose-1570

    02/01/2022, 10:03 AM
    @User correct
  • b

    bland-coat-6833

    02/01/2022, 10:05 AM
    So the 403 will cause htmx to issue an event that you can listen for an handle: https://htmx.org/docs/#requests
  • b

    bland-coat-6833

    02/01/2022, 10:05 AM
    An example of listening for an event is here: https://htmx.org/docs/#events
  • b

    bland-coat-6833

    02/01/2022, 10:06 AM
    So you'll need a little bit of JS to get the event and then update the
    div
    with an error message
1...444546...100Latest