crispy-forms, layouts, and htmx

<conjecture>
From my (admittedly cursory) review of the docs and code, the use of as_crispy_field in this manner is covered by the same paragraph in the docs as the crispy filter. i.e.:

As handy as the |crispy filter is, think of it as the built-in methods: as_table , as_ul and as_p . You cannot tune up the output. The best way to make your forms crisp is using the {% crispy %} tag with forms.

and

django-crispy-forms implements a class called FormHelper that defines the form rendering behavior. Helpers give you a way to control form attributes and its layout, doing this in a programmatic way using Python.

The implication that I draw from this is that the helpers do not apply when you use the “filter-style” methods.

(This all is based on a combination of some empirical evidence and my reading of the docs, not from any direct knowledge.)
</conjecture>

If I had this situation where I had different individual fields needing to be rendered, and depending upon the exact specifics involved, I’d be tempted to try one of the following:

  • Dynamically create the Layout object as needed.
  • Render the entire form and then use something like BeautifulSoup to extract the portion of the rendered template to be returned.

You might also want to see the thread at Adding template fragments or partials for the DTL for some other ideas.