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

    eager-psychiatrist-68229

    06/21/2022, 2:24 PM
    check this out

    https://www.youtube.com/watch?v=Fh2iDdASxjEβ–Ύ

  • a

    ancient-father-3063

    06/21/2022, 2:24 PM
    will do, thanks
  • g

    gray-morning-3453

    06/24/2022, 8:40 PM
    Hi. I am trying to build a calendar app similar to google-calendar in Django with HTMX. The general approach is that there is a background CSS grid onto which the events divs are placed by mapping the event times to the grid rows. Right now I am doing this server-side. When the template is rendered, the divs are already placed. But I am confused about adding or editing events from the client-side. Should I talk with the server in JSON? The way I understand this is that the calendar grid should remain as it is and javascript should get events data dynamically and display it as event divs onto the grid. But this goes against the HTMX philosophy of returning HTML from the server. Should I refresh the whole calendar container div after an add/edit event? If I do that I won't be able to implement a click&drag feature for the events. I am confused. What are your thoughts?
  • h

    hundreds-camera-24900

    06/24/2022, 10:26 PM
    I think submitting json is fine, although it might be more htmx-y to use form data
  • h

    hundreds-camera-24900

    06/24/2022, 10:26 PM
    For loading data in I think you could just have one oob swap per event
  • g

    gray-rocket-3571

    06/24/2022, 11:19 PM
    Will events span multiple days?
  • g

    gray-rocket-3571

    06/24/2022, 11:38 PM
    If an event won’t span multiple days, and if you have each div inside your grid an β€œid” that holds events for that day, you could return a success message plus another div with the hx-swap-oob to replace just that one div inside of your calendar div
  • g

    gray-morning-3453

    06/24/2022, 11:52 PM
    Yes, but although the event can span multiple days, each day has a separate instance in db and in the interface, a separate div(just like g cal)
  • a

    aloof-crayon-56651

    06/26/2022, 12:13 PM
    Hey guys, I installed django-htmx, downloaded the htmx.min.js file from UNPKG and put it in my static folder, but I get an error in the console.
  • a

    aloof-crayon-56651

    06/26/2022, 12:14 PM
    If I install via CDN, HTMX works fine.
  • a

    aloof-crayon-56651

    06/26/2022, 12:18 PM
    Ah, I found my problem. I downloaded the page, not just the JS file. lol
  • b

    blue-ghost-19146

    06/26/2022, 10:36 PM
    How do people approach Django views with htmx? E.G. a full page that has a fragment(s) within it. We write a view for the whole page (called on first page load), then write separate views for any fragments on that page. This results in quite a bit of repeated code to provide the correct context to each view. Any thoughts / experiences / solutions?
  • h

    hundreds-camera-24900

    06/27/2022, 2:37 AM
    I've seen one approach which is surrounding your site chrome with if tags
  • h

    hundreds-camera-24900

    06/27/2022, 2:38 AM
    And then choosing in the view a different template like so: https://django-htmx.readthedocs.io/en/latest/tips.html#partial-rendering
  • a

    aloof-crayon-56651

    06/27/2022, 4:17 AM
    I need to learn how to respond to invalid data in a django form.
  • a

    aloof-crayon-56651

    06/27/2022, 4:18 AM
    I have a contact form with a confirmation step.
  • a

    aloof-crayon-56651

    06/27/2022, 4:19 AM
    The code looks like this.
  • a

    aloof-crayon-56651

    06/27/2022, 4:19 AM
    During the confirmation step, the form is validated by Django.
  • a

    aloof-crayon-56651

    06/27/2022, 4:24 AM
    Oh, I think I got it.
  • a

    aloof-crayon-56651

    06/27/2022, 5:14 AM
    Got my contact form working perfect with a touch of hyperscript. πŸ’ͺ
  • b

    blue-ghost-19146

    06/27/2022, 5:37 PM
    Thanks for sharing @hundreds-camera-24900
  • r

    red-caravan-17890

    06/29/2022, 5:18 PM
    Hi all -- I'm building a django app and I want to change an link to use hx-put instead of get and return a normal response..in this case a csv. How do I do this?
  • m

    mysterious-toddler-20573

    06/29/2022, 5:55 PM
    if you want it to download the file, ajax won't work unfortunately, you'll need to keep it a "normal" link
  • h

    hundreds-camera-24900

    06/29/2022, 11:24 PM
    Has anyone ever created a message in a test outside of a view? I've always done the thing where you post a form and then test that the message was created
  • h

    hundreds-camera-24900

    06/29/2022, 11:24 PM
    but I want to test the display in a general case so I need to progrmatically create a message
  • h

    hundreds-camera-24900

    06/29/2022, 11:25 PM
    first try is:
    Copy code
    python
        def test_initial_load(self):
            request = self.factory.get('/')
            messages.success(request, 'this is a test message')
    
            page = self.context.new_page()
            page.goto(f"{self.live_server_url}{self.url}", wait_until="networkidle")
            locator = page.locator('#messages')
            expect(locator).to_be_visible()
  • h

    hundreds-camera-24900

    06/29/2022, 11:25 PM
    which fails because the requestFactory doesn't do middleware, so the message can't be created due "django.contrib.messages.api.MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware"
  • n

    numerous-autumn-29441

    07/01/2022, 1:56 PM
    Hi everyone! I'm learning HTMX and using it alongside django for an application. I'm having a bit of a problem with hx-prompt. I need to pass the prompt text inside hx-vals for the django view - it will be the name of a model to be saved. I've read the documentation regarding hx-prompt and the dialogs example, but for it to work like that I would need to use a div with display:none, and another requisition with hx-trigger='change' on the div, which would be double the code. In short, is there any way to pass a text the user sends through prompt directly in the same requisition?
  • l

    late-king-98305

    07/01/2022, 5:19 PM
    Can you read it server-side from the HTTP headers? https://htmx.org/attributes/hx-prompt/
  • a

    astonishing-kilobyte-60820

    07/04/2022, 1:32 AM
    this should help
1...626364...100Latest