[Django] #33819: Add multiple template render support

95 views
Skip to first unread message

Django

unread,
Jul 1, 2022, 9:48:45 AM7/1/22
to django-...@googlegroups.com
#33819: Add multiple template render support
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
thomasdebonnet |
Type: New | Status: new
feature |
Component: Template | Version: 4.0
system | Keywords: HTMX, render,
Severity: Normal | template
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
After extensive use of HTMX and Django I found the need to have a multiple
render template system. This is because i'm creating more and more
partials (small template with a specific purpose).

What is good about this new feature is that you can string together
multiple templates, provide one context, and render it as one template.
This is particularly handy when using HTMX, because you can string
together multiple small templates, and HTMX will pickup on them and
replace the corresponding HTML (this is done with hx-swap-oob)

This makes the backend very flexible and customizable.

The code would live in django.shortcuts and would look like this:
{{{
def render_multiple(request, template_names, context):
rendered_html = ""
for template_name in template_names:
rendered_html += render_to_string(
template_name, context=context, request=request
)

return HttpResponse(rendered_html)
}}}


It basically loops over render_to_string, and returns a rendered template.

In the view it could be used like this:

{{{
return render(
request,
["foo.html", "bar.html"], # note the list
context,
)

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33819>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 1, 2022, 10:38:26 AM7/1/22
to django-...@googlegroups.com
#33819: Add multiple template render support
-------------------------------------+-------------------------------------
Reporter: Thomas De Bonnet | Owner: Thomas De
| Bonnet
Type: New feature | Status: assigned
Component: Template system | Version: 4.0
Severity: Normal | Resolution:
Keywords: HTMX, render, | Triage Stage:
template | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Thomas De Bonnet):

* owner: nobody => Thomas De Bonnet
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33819#comment:1>

Reply all
Reply to author
Forward
0 new messages