Live data from Hacker News

Some more things about Django I've been enjoying

jvns.ca

101–110 of 128 posts

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

#101
post #57

Not to be a downer since a lot of JEvans’ content is great. People should really give .NET a try. I don’t know if we are just old greybeard curmudgeons who look at this and go “is this a new thing? haven’t we been doing this for decades?”, but .NET out of the box with a few packages for databases, logging, etc is so pleasant you don’t even think about it. Maybe it’s just not a vocal community idk.

agreed 100%, the most under-appreciated programming ecosystem of them all. It's also the only one that has support for making truly native apps for all four major platforms: Windows, Linux, MacOS and iOS. If you're willing to put in the work and make separate, native UIs for each, C# is the only way to go. It's a rich enough language that it binds reasonably well to both Java (on Android) and Objective C / Swift (on…

How is this different from any other language? Python can also make apps for all those platforms, either with native UIs or cross-platform UIs. There are many options.

Are you talking about .NET's AOT compilation and that's why you say "truly native"?

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

#102

Earlier quoted context omitted.

Please go on. I also feel like asyncio is a big hack. Even just accidentally blocking the event loop is way too easy. And I couldn't believe it when I read that you need to store a reference to a task in a set to keep it from accidentally getting canceled. How did this become the main stack of AI backends? It's like node but slower AND much easier to mess up because of synchronous IO.

I'm not sure i see it as a hack, but i do feel unduly burdened as a developer by async in python. I feel like there's a lot that i have to think about and i'd appreciate more help from the language. I don't want to be overly critical, there's languages that people complain about and then there are languages that no one uses... If i compare it to js/ts, some stuff is genuinely better in Python - e.g. if you missed an…

Or just env PYTHONASYNCIODEBUG=1.

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

#103
post #74

Earlier quoted context omitted.

> I can't quite picture how operator overloading would look like, could you give an example? Instead of this: self.filter(end__gt=self._midnight(today)) You could write a "Field" class that implements __getattr__ and __gt__ so you could do self.filter(Field.end > self._midnight(today)) The "Field.end > self._midnight(today)" would evaluate to an object that would just store "my field name is end and my value needs to…

SQLalchemy does that. One advantage of the Django syntax is that it can be (pretty much) directly dropped into a query string on any admin page or DRF query and filter the results. E.g. the admin page for all the events after noon today: admin/event/?end__gt=2026-07-26T12:00:00 Being able to do ad-hoc queries using the same paradigm your app queries are written in, and then pass urls around with those queries include…

This convenience sounds a little dangerous. Would this allow the user to specify e.g. joins or SQL procedure calls using the query parameter?

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

#104
post #99

My experience from running a django app with thousands of migrations and dozen of apps - Testing involving models is slow. It runs all your migration. Python's own "Unittest" is fast for functions not involving models. - The suggested pattern for business logic is "active record", which is putting functions about a model alongside the model itself. Good for clean case. Doesn't really work when your operation involve…

You can run with --no-migrations (https://pytest-django.readthedocs.io/en/latest/database.html...) and default the test DB to be in memory (works at least for PG and SQLite) to make it quite a bit faster.

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

#105
Django is nice, but I'm currently migrating a project from Django to Go because Django is too large. I would love to stay with it, but simply assimilating the docs has been a chore. The PDF is 3000 pages, and I love working with tools where all the parts can fit in my head.

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

#106

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…

Thanks! Any noticeable downsides?

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

#107

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…

I think people in the Python world just don't yet have a good mental model of async either. I recently have had conversations with a number of people who have switched to FastAPI because "it's faster" even when they're using it to serve ML models which are compute bound and there's nothing you can await on.

I think the mental model is the right thing to focus on. I'm not denying there are cases where async at the edge of an app can make sense but there's no free lunch and i that doesn't appear to be well understood.

Maybe i will write a blog post, if nothing else than to get my own thoughts in order.

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

#108

> Some light load testing (with (ab -n 1000 -c 1) shows that right now we can serve about 2-3 requests per second (on a ~$10/month VM). > After turning on template caching, it seems like the site can now pretty easily handle 12 requests per second or so without using all of the CPU. I have not carefully benchmarked the before and after but it seems like it’s made a pretty big difference. That seems crazy low, I think…

Copying my comment from lobste.rs here:

I don't think the performance issues here are a result of Django. The author says only 2-3 requests per second (rps). Even in debug mode just using django runserver I can get 60~ rps on my $WORK repo. Part of this is likely their choice of only using '-c 1', which doesn't accurately represent a web workload.

For example on a local dev server I get (in format -c n. rps)

1. 58

2. 61

3. 55

as expected because we only have 1 worker, in debug with little caching.

but when looking at an example production config we see

1. 1: 11

2. 2: 23

3. 5: 54

4. 10: 95

5. 20: 153

6. 30: 165

7. 40: 177

8. 50: 192

and so on....

All of these are far in excess of the 2-3 observed by the author.

Note these will heavily depend on how many database hits you have per request as that is the majority of workload, as well as your http server such as using http 1/2/3, and the TLS settings used etc...

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

#109
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…

For lots of applications, Mercure is a great replacement for websockets and it works wonderfully with django

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

#110
post #9

I have been using Django since 0.95 and I haven't seen anything which is so flexible with amazing DSLs while also making it easy to understand the magic behind it. For the last 10 years, even in a Golang stack or Java stack, I still use Django for models and migration. I even have generators which generate Gorm (or other framework) DAO or Java hibernate classes using Django models. With LLMs, it becomes easier since…

> I still use Django for models and migration There are dozens of us! It's a great db management toolkit. I've used it to much success many times for things like managing migrations from mysql to postgres and php to python. My opinions: - Django apps are an anitipattern for large internal / single purpose products due to migration overhead as FKs cross application boundaries. I will die on this hill. No team is ever…

In go, for my personal projects only I don't think it would scale, I made my own migration tool since I am not using an ORM. It works pretty well for my use case and is quite simple.

https://github.com/oxodao/micromigrations

EDIT: Also Doctrine is really great in the Symfony world, I like it much more than django-orm

Post reply on HN