silly-bear-76516
10/13/2021, 7:09 PMbitter-dog-98292
10/14/2021, 7:16 AMbumpy-library-86484
10/17/2021, 4:14 PMsalmon-xylophone-28580
10/17/2021, 6:59 PMuser
10/19/2021, 1:28 PMmysterious-toddler-20573
10/19/2021, 1:38 PMuser
10/19/2021, 1:41 PMopen 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 bigmysterious-toddler-20573
10/19/2021, 1:45 PMHX-Redirect
response header to the location of the generated PDF. That should open the PDF in a new tab.mysterious-toddler-20573
10/22/2021, 3:05 PMhundreds-camera-24900
10/23/2021, 2:25 PMmysterious-toddler-20573
10/23/2021, 2:52 PMmysterious-toddler-20573
10/23/2021, 2:52 PMHX-Request
equal to true
and HX-Target
with the id of the target element. These can be used to adjust your response rendering.hundreds-camera-24900
10/23/2021, 2:54 PMhundreds-camera-24900
10/23/2021, 2:55 PMif request.htmx:
return render(request, "partials/edit_form.html", context)
else:
return render(request, "edit_form.html", context)
hundreds-camera-24900
10/23/2021, 2:56 PMhundreds-camera-24900
10/23/2021, 2:57 PM@render("edit_form.html", "partials/edit_form.html")
def view(request):
context = {"users":User.objects.all()}
return context
hundreds-camera-24900
10/23/2021, 2:58 PMhundreds-camera-24900
10/23/2021, 2:58 PMgorgeous-airport-54386
10/23/2021, 3:01 PMpython
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 salthundreds-camera-24900
10/23/2021, 3:02 PMhundreds-camera-24900
10/23/2021, 3:02 PMhundreds-camera-24900
10/23/2021, 3:03 PMhundreds-camera-24900
10/23/2021, 3:41 PMhundreds-camera-24900
10/23/2021, 3:42 PMhundreds-camera-24900
10/23/2021, 3:43 PMhundreds-camera-24900
10/23/2021, 3:43 PMhundreds-camera-24900
10/23/2021, 3:45 PMhundreds-camera-24900
10/23/2021, 3:45 PMhundreds-camera-24900
10/23/2021, 3:45 PMmysterious-toddler-20573
10/23/2021, 4:00 PM