Live data from Hacker News

Some more things about Django I've been enjoying

jvns.ca

111–120 of 128 posts

Re: Some more things about Django I've been enjoying

#111

Earlier quoted context omitted.

> Is Jinja2 a practical alternative or there's friction to using it? jinja2 is drop in by changing the template backend. You can actually run both at the same time (just can't mix them, ofc). https://docs.djangoproject.com/en/6.0/topics/templates/

It's a practical alternative, but definitely not a drop-in replacement! I've been working on migrating a django project to jinja2 lately, see the diff: https://framagit.org/la-chariotte/la-chariotte/-/merge_reque... A few notables differences: - many controls are now functions/variables (that's good!), and some change name, for example `{% csrf_token %}` -> `{{ csrf_input }}` - calling methods without parenthesis doe…

Yea, I was unclear. That's what I meant by "you can't mix them"... just meant using jinja2 is drop it for the backend.

I believe you just set the dirs property in the backend config to look in whatever directory / directories you want it just defaults to jinja2 as you discovered.

Re: Some more things about Django I've been enjoying

#112
post #79

Earlier quoted context omitted.

> It's like hiding the kitchen knives because they might be misused. I used to agree with this more strongly but over time decided the Django model was actually more effective as your cue to ask whether you should have been writing a Python function instead and calling it (which has been super easy since something like 1.4 or so IIRC). Unless you have a small, very diligent development team it always seemed to end up…

> over time decided the Django model was actually more effective as your cue to ask whether you should have been writing a Python function instead and calling it I get the motivation, but is disallowing brackets and proper variables really the right way to do this? These make code clearer to read and reduce duplication more than they introduce complexity so this is going too far in my opinion and feels arbitrary.

Oh, believe me, I’ve been on both sides there. My observation was that over time the burden of maintenance and on-boarding new developers pushed me from wanting more flexibility to saying that the restriction was more valuable than I thought.

Re: Some more things about Django I've been enjoying

#113
post #86

There are so many footguns[1] in async python but it really has stolen the zeitgeist of modern python web. Synchronous django has a lot to commend it. If you deploy it reasonably well (workers, behind a caching reverse proxy etc) it's easy to operate in production even under duress. It's not going to be the right stack for long lived websocket connections or whatever but for a CRUD-ish or enterprise app, often very p…

Everytime I have to deal with websockets in Django, I want to rip my eyeballs out. Most of the time what I really want is just push support, and don't need bidirectional communication, i.e. SSE. But it's the same thing: both are a pain to work with in Django. I find django-channels so cumbersome. So, for my latest projects, I've ended up offloading this push functionality to a service like Centrifugo. Django talks to…

You don't need django-channels anymore for SSE: https://docs.djangoproject.com/en/6.0/ref/request-response/#...

Re: Some more things about Django I've been enjoying

#114
post #92

automatic migrations terrifies me. i use elixir/ecto. just write a migration! besides, some times you might want more than one schema for a db table (e.g. one with minimal information, for menus, dropdowns etc, and one with full information for your full CRUD operations)

> some times you might want more than one schema for a db table Django has the concept of "proxy models" where you can define a trimmed down model for the same database table.

what if two models access disjoint sets of fields (like a Data.Admin and Data.User)

Re: Some more things about Django I've been enjoying

#115
post #65
post #5

Earlier quoted context omitted.

Those numbers sound... Single-threaded. Like they're using the development runserver instead of uwsgi or gunicorn.

Development runserver has been multithreaded by default for over a decade. I think you need to go back to major version 1 to see it single-threaded by default. Maybe affected by the GIL though.

Pretty sure it still defaults to no threading [0], and just uses the plain WSGIServer instead of the threaded mixin.

[0] https://github.com/django/django/blob/main/django/core/serve...

Re: Some more things about Django I've been enjoying

#116

Earlier quoted context omitted.

It's a practical alternative, but definitely not a drop-in replacement! I've been working on migrating a django project to jinja2 lately, see the diff: https://framagit.org/la-chariotte/la-chariotte/-/merge_reque... A few notables differences: - many controls are now functions/variables (that's good!), and some change name, for example `{% csrf_token %}` -> `{{ csrf_input }}` - calling methods without parenthesis doe…

Yea, I was unclear. That's what I meant by "you can't mix them"... just meant using jinja2 is drop it for the backend. I believe you just set the dirs property in the backend config to look in whatever directory / directories you want it just defaults to jinja2 as you discovered.

From what i understand `DIRS` is only for the top-level app. I couldn't find a way to apply it to inner apps (eg. `auth`, `order`, `etc`). I'd be happy if you know the way i don't have to rename all the template folders!

Re: Some more things about Django I've been enjoying

#117

Earlier quoted context omitted.

It's a practical alternative, but definitely not a drop-in replacement! I've been working on migrating a django project to jinja2 lately, see the diff: https://framagit.org/la-chariotte/la-chariotte/-/merge_reque... A few notables differences: - many controls are now functions/variables (that's good!), and some change name, for example `{% csrf_token %}` -> `{{ csrf_input }}` - calling methods without parenthesis doe…

Thanks! Any noticeable downsides?

For now, no. But to be fair, it hasn't reached prod yet. So far, only great upsides: developer experience (in templates) is considerably better, and djlint/j2lint make it even better (one for HTML validation through the templating, the other for jinja syntax).

Also, it should be considerably faster to render, but i haven't properly measured yet. I just know on lower hardware, the django template "static" homepage (rendered, but no conditionals and no DB calls) takes average 23ms to serve with variations 14-53ms, while a real static page takes 3ms average with 1-6ms (that's all on localhost so no network instability is measured). Can't wait to have the jinja stats!

Re: Some more things about Django I've been enjoying

#118
post #112

Earlier quoted context omitted.

> over time decided the Django model was actually more effective as your cue to ask whether you should have been writing a Python function instead and calling it I get the motivation, but is disallowing brackets and proper variables really the right way to do this? These make code clearer to read and reduce duplication more than they introduce complexity so this is going too far in my opinion and feels arbitrary.

Oh, believe me, I’ve been on both sides there. My observation was that over time the burden of maintenance and on-boarding new developers pushed me from wanting more flexibility to saying that the restriction was more valuable than I thought.

[deleted]

Re: Some more things about Django I've been enjoying

#119
post #92

Earlier quoted context omitted.

> some times you might want more than one schema for a db table Django has the concept of "proxy models" where you can define a trimmed down model for the same database table.

what if two models access disjoint sets of fields (like a Data.Admin and Data.User)

Two proxy models that extend the same base model.

Re: Some more things about Django I've been enjoying

#120

There are so many footguns[1] in async python but it really has stolen the zeitgeist of modern python web. Synchronous django has a lot to commend it. If you deploy it reasonably well (workers, behind a caching reverse proxy etc) it's easy to operate in production even under duress. It's not going to be the right stack for long lived websocket connections or whatever but for a CRUD-ish or enterprise app, often very p…

async python is always slower than just naively using threads. I don't think there is any application in production anywhere that would not prove me right on this. the complete lack of any kind of scheduling is a disaster. unless you know exactly what I mean by a scheduler please don't reply to this.

I don’t think there’s anything Python specific about that criticism. Most languages with cooperative concurrency have simple or no schedulers and run coroutines pretty much directly (or unpredictably, if they’re scheduled into parallel executors). Even Java and Tokio’s scheduling, such as it is, isn’t that directly controllable or observable and doesn’t magically fix loop-blocking or cache efficiency or whatever.

I think you might just not like cooperative async IO multiplexing as a programming model. Which is fine, but has nothing to do with Python.

Post reply on HN