4 ms·
Can you elaborate on the render fragment on GET/POST part? That sounds interesting!
by number6 5y ago
Can you elaborate on the render fragment on GET/POST part? That sounds interesting!
- brylie 5y agoSee the following video tutorial starting at 9:18 for an example of rendering a template fragment in a Django view that gets returned to HTMX https://youtu.be/H_m1g8XOtHY https://youtu.be/H_m1g8XOtHY
- theptip 5y agoIf 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.