Exciting to see people start to pick up template-partials with Django 6.0.

“Wait until you hit upon using them for form field templates”, I quietly whisper 🥳

@carlton 👀 such a tease! a quick blog post perhaps?
@nanorepublica “quick” and “blog post” just sat there next to each other 😝
@carlton haha 😂 maybe just a code snippet then?
Comparing django:main...codingjoe:esupgrade · django/django

The Web framework for perfectionists with deadlines. - Comparing django:main...codingjoe:esupgrade · django/django

GitHub

@adamchainz @nanorepublica @davidsmith Yeah, it's a lot simpler.

But it's the super powers it unlocks that are most fun. 🤩

(Yes, @nanorepublica, busy writing ✍️)

@carlton @adamchainz @nanorepublica
Nice. 👍 (assuming we are happy to adjust the output)

If I had a magic wand I'd change the api so that you can avoid unpacking (field, errors) where `errors` is unused.

@carlton I made my own crude partials exactly because of form fields. I'm keen to upgrade to 6.0 and replace that.

@carlton I overrode a form renderer at some point in the past, and it was ugly.

I also needed specific HTML classes based on input type for styling, which, luckily, has been superseded by CSS's `:has()` selector.

Such a long way from this clean template solution, and I love it.

@mahryekuh it’s got a lot nicer in recent years. Partials is the little cherry on top, allowing really neat per field overrides 🍒

(Yes @nanorepublica busy writing ✍️)

@carlton if you want to define a partial in a separate file for reuse across your app, what is the pattern for that? The docs seem to demonstrate definition and use within the same file?
@onionarmy that would just be an include, same as ever.

@carlton hm.. I see the docs mention; "Template partials can also be included using the include template tag with the same # directive:"

Though I still get "Partial 'journal-metadata' is not defined in the current template."

That's with using;

{% include "example.html#journal-metadata" %}

I have to dig further into that.

But do partials have to be included one by one? Can you import all partials in bulk?

Something like:

{% include "example.html %}

?

@onionarmy you reference them by name individually. I’d just suggest you play with them. They’re fun! 🤩
@carlton hm.. for some reason the include syntax for partials doesn't load the partials for me. Doing a normal include of the file that contains it works, so the template file is found.
I'll ask in the forums.