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

    silly-bear-76516

    10/13/2021, 7:09 PM
    https://github.com/ajcerejeira/talksapp https://github.com/adamchainz/django-htmx https://github.com/jacklinke/django-htmx-todo-list https://github.com/MattSegal/django-htmx-intro Here are a few repos with examples ^
  • b

    bitter-dog-98292

    10/14/2021, 7:16 AM
    I also found this one which is nice : https://github.com/justdjango/django_htmx_dynamic_forms
  • b

    bumpy-library-86484

    10/17/2021, 4:14 PM
    I'm getting a 403 when trying to use the link from the repo back to the tutorial
  • s

    salmon-xylophone-28580

    10/17/2021, 6:59 PM
    Could you please check this again, and then create an issue du that the maintainer knows about it?
  • u

    user

    10/19/2021, 1:28 PM
    Hi. Is it possible to hx-target a new tab? I have an url that make a precompiled pdf but I need the info from a form to do it that I was planning to hx-post to the URL
  • m

    mysterious-toddler-20573

    10/19/2021, 1:38 PM
    can you post some code? When you say a new tab, do you mean open the pdf in a new tab?
  • u

    user

    10/19/2021, 1:41 PM
    open the pdf in a new tab?
    yes exactly that. I will try to come up with an example since the whole code is way too big
  • m

    mysterious-toddler-20573

    10/19/2021, 1:45 PM
    OK, what you probably want to do is respond with a
    HX-Redirect
    response header to the location of the generated PDF. That should open the PDF in a new tab.
  • m

    mysterious-toddler-20573

    10/22/2021, 3:05 PM
    https://twitter.com/htmx_org/status/1451565326521573379
  • h

    hundreds-camera-24900

    10/23/2021, 2:25 PM
    Is there something similar to https://github.com/skorokithakis/django-annoying#render_to-decorator that makes a distinction between a full page refresh and a partial?
  • m

    mysterious-toddler-20573

    10/23/2021, 2:52 PM
    htmx includes multiple request headers: https://htmx.org/reference/#request_headers
  • m

    mysterious-toddler-20573

    10/23/2021, 2:52 PM
    including
    HX-Request
    equal to
    true
    and
    HX-Target
    with the id of the target element. These can be used to adjust your response rendering.
  • h

    hundreds-camera-24900

    10/23/2021, 2:54 PM
    yeah I've been playing around with django-htmx which will add a request.htmx attribute
  • h

    hundreds-camera-24900

    10/23/2021, 2:55 PM
    it's easy ehough to do something like
    Copy code
    if request.htmx:
      return render(request, "partials/edit_form.html", context)
    else:
      return render(request, "edit_form.html", context)
  • h

    hundreds-camera-24900

    10/23/2021, 2:56 PM
    but I think a nicer api would be something more like
  • h

    hundreds-camera-24900

    10/23/2021, 2:57 PM
    Copy code
    @render("edit_form.html", "partials/edit_form.html")
    def view(request):
       context = {"users":User.objects.all()}
       return context
  • h

    hundreds-camera-24900

    10/23/2021, 2:58 PM
    interesting idea to vary the response based on HX-Target
  • h

    hundreds-camera-24900

    10/23/2021, 2:58 PM
    but that feels a little fragile
  • g

    gorgeous-airport-54386

    10/23/2021, 3:01 PM
    Copy code
    python
    def hx_render(fullpage, partial):
      def decorator(func):
        @wraps(func)
        def wrapper(request, args, **kwargs):
          context = func(request, *args, **kwargs)
          if request.htmx:
            return render(request, partial, context)
          else:
            return render(request, fullpage, context)
    
        return wrapper
    
      return decorator
    i haven't touched python in a while and i also don't have django experience, so take this with a grain of salt
  • h

    hundreds-camera-24900

    10/23/2021, 3:02 PM
    yeah I guess looking at https://github.com/skorokithakis/django-annoying/blob/master/annoying/decorators.py#L58 it's not really doing much more then that
  • h

    hundreds-camera-24900

    10/23/2021, 3:02 PM
    you use a third party app that does something simple and I always assume there's some kind of hidden complexity that I would need to manage to do myself
  • h

    hundreds-camera-24900

    10/23/2021, 3:03 PM
    I guess the only thing that would need to add to be feature complete would be the typecheck on the response to allow the function to return a complete reponse
  • h

    hundreds-camera-24900

    10/23/2021, 3:41 PM
    This might be a stupid question but I'm throwing together a form + generic view that will be embeded on another page
  • h

    hundreds-camera-24900

    10/23/2021, 3:42 PM
    IE if "thing" is the host page, there's a form on thing to control UserRatingForThing that will post to a different location and 302 back to thing
  • h

    hundreds-camera-24900

    10/23/2021, 3:43 PM
    I planned on a text box for rating and a button to create a new UserRatingForThing (add to list)
  • h

    hundreds-camera-24900

    10/23/2021, 3:43 PM
    and then once it's added you'd update the rating on focus out, and the button would switch to "remove from list" and act as delete
  • h

    hundreds-camera-24900

    10/23/2021, 3:45 PM
    I just sort of had in my head that I'd have one endpoint and would manage the different actions (create, update, delete) through http verbs EG hx-delete on the button after it's been added, hx-put on the text area, and hx-post on the button to add
  • h

    hundreds-camera-24900

    10/23/2021, 3:45 PM
    I've been in the rest world for a while so I just naturally went that way
  • h

    hundreds-camera-24900

    10/23/2021, 3:45 PM
    But it's more idomatic to just drive that all through POST right? and then vary on the url
  • m

    mysterious-toddler-20573

    10/23/2021, 4:00 PM
    not a djano person, but I think one of best aspects of htmx is that it allows you to use the full constellation of HTTP request types to implement a really REST-ful HTTP/HTML api
1...91011...100Latest