3 ms·
If you use django-htmx, it's pretty simple to get the "this HTTP request came from HTMX" flag and branch accordingly in your view. The docs give a simple exampl
by theptip 5y ago
If you use django-htmx, it's pretty simple to get the "this HTTP request came from HTMX" flag and branch accordingly in your view. The docs give a simple example of the logic here:
https://django-htmx.readthedocs.io/en/latest/middleware.html#django_htmx.middleware.HtmxDetails https://django-htmx.readthedocs.io/en/latest/middleware.html...
The examples give a fleshed-out version: https://github.com/adamchainz/django-htmx/blob/main/example/example/core/views.py#L107-L127 https://github.com/adamchainz/django-htmx/blob/main/example/...
Though that's very slightly different than how I described it above, but it's basically the same idea; in this case you commonize the `main` block between the two contexts.