Live data from Hacker News

Django: what’s new in 6.0

adamj.eu

81–90 of 127 posts

Re: Django: what’s new in 6.0

#81

Earlier quoted context omitted.

Key benefit for reusability and composability in React is IMHO that they don't use templates at all, but everything is a function.

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.

iommi is wroth mentioning here. It is different from an HTML generator, but one of the things it does is greatly reduce the amount of HTML you need write.

Re: Django: what’s new in 6.0

#82
post #72

Earlier quoted context omitted.

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.

There are a lot of cool things about these, one that they are less typo prone and also they are often much faster. The downside is I find them hard to read. I think the template approach isn't quite right and yet neither is the functional approach. At the end of the day these are a type of tree structure; I think we could conjure a new mechanism that gets the best of most/both worlds.

Yeah, I agree, I find them hard to read. JSX is the best thing I've used. Elsewhere in the thread someone mentioned Cotton which seems to strike a different balance.

To be honest my main problem with templates is they have to be one per file. In principle there's no difference between naming a new file and naming a function, but in practice it just sucks. It's a higher barrier so people are less likely to write smaller components, and refactoring support completely sucks. Even renaming a template is a massive pain whereas renaming a function with decent LSP support is easy.

JSX hits that perfect balance between readability while still being regular functions. Maybe something is possible with the new 3.13 template strings?

Re: Django: what’s new in 6.0

#83
I find templates atrocious to use for component fragments like this, that's why I wrote a Python component library when I started using Django with HTMX. Order of magnitude more pleasant to use, works with _every_ Python web framework not just Django: https://compone.kissgyorgy.me/

Re: Django: what’s new in 6.0

#84

Earlier quoted context omitted.

Key benefit for reusability and composability in React is IMHO that they don't use templates at all, but everything is a function.

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.

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?

Re: Django: what’s new in 6.0

#85

Template Partials and HTMX seems like the Django equivalent of View Components and Stimulus for Rails, which is nice. Also, good to see first class support for Tasks, among a lot of other niceties!

Rails renders partials

https://guides.rubyonrails.org/layouts_and_rendering.html#pa...

Re: Django: what’s new in 6.0

#86
post #45

Earlier quoted context omitted.

Celery is great and awful at the same time. In particular, because it is many Python folks' first introduction to distributed task processing and all the things that can go wrong with it. Not to mention, debugging can be a nightmare. Some examples: - your function arguments aren't serializable - your side effects (e.g. database writes) aren't idempotent - discovering what backpressure is and that you need it - losing…

> your side effects (e.g. database writes) aren't idempotent What does idempotent mean in this context, or did you mean atomic/rollback on error? I'm confused because how could a database write be idempotent in Django? Maybe if it introduced a version on each entity and used that for crdt on writes? But that'd be a significant performance impact, as it couldn't just be a single write anymore, instead they'd have to d…

Here is a nice guide from AWS https://docs.aws.amazon.com/wellarchitected/latest/framework...

Re: Django: what’s new in 6.0

#87

Earlier quoted context omitted.

Why is celery awful?

> The Many Problems with Celery: — https://steve.dignam.xyz/2023/05/20/many-problems-with-celer... > The problems with (Python’s) Celery: — https://docs.hatchet.run/blog/problems-with-celery > Dramatiq motivation: — https://dramatiq.io/motivation.html Here are some alternatives: Dramatiq: https://github.com/Bogdanp/dramatiq RQ: https://github.com/rq/rq Huey: https://github.com/coleifer/huey Hatchet: https://github.co…

Would you consider tools like Temporal, DBOS, Absurd Workflows, PGQueuer as alternatives?

https://temporal.io/

https://docs.dbos.dev/

https://news.ycombinator.com/item?id=45797228

https://python-absurd-client.readthedocs.io/en/latest/quicks...

https://pgqueuer.readthedocs.io/en/latest/

Re: Django: what’s new in 6.0

#88
post #60
post #58

Given that Python tends to produce fewer hallucinations when generated by LLMs I wonder if former Django developers using AI tools are secretly having a blast right now.

I think another ace up Django's sleeve is that it has had a remarkable stable API for a long time with very few breaking changes, so almost all blogposts about Django that the LLM has gobbled up will still be mostly correct whether they are a year or a decade old. I get remarkably good and correct LLM output for Django projects compared to what I get in project with more fast moving and frequently API breaking framew…

The "one way" / "batteries included" aspect of Django may also make it easier for LLMs

Re: Django: what’s new in 6.0

#89
post #45

Earlier quoted context omitted.

> your side effects (e.g. database writes) aren't idempotent What does idempotent mean in this context, or did you mean atomic/rollback on error? I'm confused because how could a database write be idempotent in Django? Maybe if it introduced a version on each entity and used that for crdt on writes? But that'd be a significant performance impact, as it couldn't just be a single write anymore, instead they'd have to d…

In the context of background jobs idempotent means that if your job gets run for a second time (and it will get run for a second time at some point, they all do at-least-once delivery) there aren't any unfortunate side effects to that. Often that's just a case of checking if the relevant database updates have already been done, maybe not firing a push notification in cases of a repeated job.

If you need idempotent db writes, then use something like Temporal. You can't really blame Celery for not having that because that is not what Celery aims to be.

Re: Django: what’s new in 6.0

#90
post #3

Any code or blog written by Adam is worth spending some time on. It will be interesting to see how the tasks framework develops and expands. I am sad to see the great Django-Q2 lumped in with the awful Celery though.

I'm of the opinion that django task apps should only support a single backend. For example, django-rq for redis only. There's too many differences in backends to make a good app that can handle multiple. That said, I've only used celery in production before, and I'm willing to change my mind.

Why have a backend then?
Post reply on HN