Okay, the title is a bit strange, bear with me for a second while I explain.
When I was figuring out how htmx and django played together, I stumbled upon the fact that if you you hx-push-url="true"
and that url is a view with a partial template (such as would be used for hx-get), it rendered only that partial. At first I thought, "oh, right. that won't work." So your solution here with checking if a request is request.htmx
or not solves that problem nicely.
But then I realized... it could actually be extremely useful for development and testing. When I rendered just that one form I was testing, outside of the context of the rest of the page, it was... really nice. I could hone in on just the component that I was testing, coming from that view. In the case of a modal, the rest of the page is pretty irrelevant when I want to test and develop just that modal in isolation.
So what I started doing was, I had a base.html
template that looked like this:
<!DOCTYPE html>
<html>
<head>
<title>Stocker!</title>
<script src="https://unpkg.com/[email protected]" integrity="sha384-t37OW0DbqgL50XZW+Tl8TLchxsPoxIJ7NQ/l4aSZIXZVJQAhyQvvkWZgL/SiY/jD" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
</head>
{% block base %}
{% endblock %}
</html>
and a base_body.html
template that actually contained my 'base layout', my navbar, my structural stuff.
My "pages", like the home page, extend base_body.html
and are fully part of the layout.
My "components", like a modal, extend "base.html" so that they get the relevant scripts and css etc, but are rendered in isolation.
So my thought is, can I have both this "render just this component for testing and debugging and stuff" request path, and the dual "partial vs complete" path as demonstrated in your demo? Is that feasible? (More importantly, do I really want it? When I demo it to colleagues, they think it's potentially a really cool feature, but maybe it's silly.) Could there be some sort of DEBUG
related flag that allows you to render the partial in a request or in a test?
Thanks for hearing my rambling. Hope some of that made sense.