←back to thread

378 points rbanffy | 1 comments | | HN request time: 0.201s | source
Show context
giancarlostoro ◴[] No.46210692[source]
Template partials look good, which is one of the key reasons frameworks like React are as good and popular as they are, because you can reuse small segments of code.
replies(8): >>46211187 #>>46211247 #>>46211354 #>>46211402 #>>46211982 #>>46212701 #>>46212849 #>>46213424 #
littlecranky67 ◴[] No.46211982[source]
Key benefit for reusability and composability in React is IMHO that they don't use templates at all, but everything is a function.
replies(1): >>46214928 #
globular-toast ◴[] No.46214928[source]
Exactly. There are a few libraries to achieve a similar thing in Python:

* https://htpy.dev/

* https://pypi.org/project/fast_html/

* https://fastht.ml/ (different to above, I think)

* https://github.com/volfpeter/fasthx

Probably others. I strongly prefer this to templating, but I find it makes dyed in the wool Django people squirm.

replies(3): >>46216164 #>>46216606 #>>46216700 #
dontwannahearit ◴[] No.46216700[source]
I like this approach. I am especially drawn to the idea of making custom components this way but every time I have experimented with this I get burned by the context which has to be passed down through all functions.

A jinja/django template has an implicit context but for nested functions you really have to pass that context down through every function call.

It inevitably ends up just a big dict blob.

You get some typing support in an IDE but nothing really for function parameters.

Maybe I am doing wrong?

replies(1): >>46218272 #
1. pelme ◴[] No.46218272[source]
htpy supports passing data between multiple levels components with its context (very similar to React):

https://htpy.dev/usage/#passing-data-with-context