Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • Ah the old debate about function-based views and class-based views.

    I totally understand why the OP would use only FBV, however when writing REST APIs you will want CBV to reuse base classes such as ListView.

  • I'd love Django, if they had a better async story ... I used it for a recent project. While the framework is overall amazing, I had to switch to Go for better performance and easier async support.
  • Django-Bolt is one of the interesting projects I found recently that helps boost RPS for Django by handling HTTP requests via Rust.

    https://github.com/dj-bolt/django-bolt

  • The only part I don't really agree with, is the avoidance of app separation and signals. It's one of the cleanest ways to decouple your modules and keep some level of sanity in a medium-sized codebase. It comes down to deciding what parts really need to depend on others and be very explicit about that.

    I generally end up with a few core apps with the main data objects that a lot of other "parallel" ones depend on, a bit "star shaped". And then a few "aggregator" apps that cover functionality that needs to work across multiple of these domains. I see it all as an extension of how you think about your data model.

    by phn
  • I always wonder about signals. I found them incredibly attractive from a code cleanliness standpoint, but every team I’ve joined avoided them either because they got burnt by them or because of superstition from blog posts by people who got burnt by them. It may be a cognitive load thing, that in smaller codebases it’s easy enough to remember “these three things fire a signal when saved”, but bites you in the ass when trying to make a quick patch for a bug in production late in the day because a customer called up screaming.
  • I haven’t used Django for a long time but when I did I found it one of the best documented projects out there.
  • Sometimes I find the examples lacking a bit. For example: https://docs.djangoproject.com/en/6.0/ref/class-based-views/... Each view deserves an example, that uses the most relevant fields to specify the behavior of that view, and perhaps a minimal template example for rendering that view, and at least one of the examples should be using forms.

    This is where asking an LLM for an example is very useful, but ideally, I should be able to find the available fields and their explanation and when to use them at a glance in the docs.

    In general the docs are good, just examples could be better.

  • I really like django, but since being involved in it from early days, whenever someone now praises Django, I am reminded of this talk: https://www.youtube.com/watch?v=i6Fr65PFqfk

    DjangoCon 2008 Keynote: Cal Henderson

  • what's wrong nowadays w/ django?
  • I too often think of things as frozen in time two decades ago.
  • I remember, when I used it for the very first time in commercial project. Client briefed me in the afternoon, the next day, before the noon, she got ugly app, but with fully working admin backend. She was sold.

    But I also remember, that some non-standard requirements were really difficult to implement or get around.

    Having that in mind, the next project was entirely in Pylons. All was good, until we were asked to add Unicode support.

    Since them I'm on Rails.

  • > Having that in mind, the next project was entirely in Pylons. All was good, until we were asked to add Unicode support.

    How long ago was this? I feel like unicode has kind of been a solved problem in Python since python3 came out. In the python2 days it was, indeed, miserable.

  • I feel sufficiently old after having read South in this article. Good god what a throwback.

    Django is hands down one of my favorite frameworks ever created, and the only one I still reach for in some contexts. For a lot of projects I use it to drive database migrations, and stand up an easy admin portal for others to use - then anything else is driven by an API layer written in (e.g) Rust.

    I haven't had to care about Django's performance in years but still get to reap some of the benefits.

  • How do your API calls get into the Django app(s)? Do you define the API as well on the Django side (duplicating the API)? Or is there some tool that translates the Rust API calls for Django efficiently?
  • Nice.

    I've been meaning to do my own Django post, on some other bits we take for granted - I should do it.

    People should be using Django, the best parts are so useful you don't notice them until you switch platforms and implement them badly.

    Every app that used a more narrow solution ultimately ends up implementing parts of Django badly.

    The best way to solve this from Djangos side would be to have official ways of:

    - Using the ORM outside of Django - Doing single file Django apps

    Both of these have various 3rd party solutions, which shows demand.

    In the past other bits of Django have been split off by 3rd parties but those two are the places to start.

  • I'm sure there must be a way to just set up enough of the Django environment to mangle about at objects in your models in a program. It's something I find myself using the Django shell often enough to want to do from outside there.
  • Shout out to nanodjango, I researched all the single file options I could find some time ago and it had the best ergonomics imo. Not affiliated, just a fan.

    https://nanodjango.dev/

  • Django while opinionated is very flexible too. unlike Rails.

    that means you can mold it to fit your use case easily - don't like the ORM - you can plug SQLalchemy and use a different 'architecture'. + you can use multiple different databases if you think that's the right path. in Django there's no 'the rails way' - you choose your own path.

    Django-admin by itself saves so much work specially If you're doing B2B stuff & you gotta onboard users.

    I guess Django is not the best thing, but not the worst thing either. so a perfect middle ground.

  • also Rails largely sits in a world where most apps are CRUD based or everything is CRUD e.g [0] - which for that purpose Rails has nice ergonomics.

    whereas Django though it also provides almost similar abstractions in terms of CRUD - it doesn't assume your app will only do CRUD stuff - hence the flexibility e.g there's many apps where you only have a handful of endpoints that are user accessible maybe at most 15, then of course management of users via Django-admin but everything else is non CRUD e.g calling other systems

    [0]: https://jeromedalbert.com/how-dhh-organizes-his-rails-contro...

  • Rails is flexible too. Everything that you mentioned here can also have the sample flexibility in Rails: You can use Arel and skip AR, you can use Plex instead of HTML and so on.

    The Rails Way is a response to people changing too much Rails and making it super custom.

    In the last 4 years alone I touched codebases ranging from Rails Way to Rails and everything dry.rb, to Rails and Grape and Sorbet, to Rails and service objects everywhere and a lot more combinations.

  • Django for Startup Founders: A better software architecture for SaaS startups and consumer apps: https://web.archive.org/web/20210624040717/https://alexkrupp...

    This article is very useful.

    I use DRF but not serializers and write validations by hand because it is too abstract for me.

    My views just call services and return the result.

  • Have you seen django-bolt? Might interest you, your setup sounds like it would benefit from it.

    https://github.com/dj-bolt/django-bolt

  • Most loved feature, for me: No dramatic changes, just sane and careful evolution.
  • This is so important. I've been using Django for around 20 years and my current code base is 10 years old. Not having to do major rewrites or stick on outdated versions really matters.
  • I really like the ORM and the migrations, but some parts I really dislike. They're maybe not Django's fault, but how it's used most places:

    * Models being passed around everywhere, queries happening everywhere. I prefer having a dedicated service/selector layer to do those things. Then convert to pydantic objects or something that's passed around further.

    * Corollary, but adding stuff to querymanagers quickly goes out of control. Sure, it's nice to reuse MyModel.objects.annotate_something().annotate_something_else().... but it can quickly become unwieldy and even wrong with exploding joins. And it promotes doing queries in places they shouldn't happen.

    * It's veeery easy to make spaghetti. Very easy to query across boundaries, into other apps. Fine on smaller projects, but in huge codebases it quickly makes things hard to control, especially since it's all stringly typed. If I want to modify my model, it's hard to know if someone else have done a query where they did theirmodel__some_relation__another_relation__mymodel__some_field. Blows up in production.

    * For some reason it's very common in Django/python projects to have types.py, models.py, selectors.py, views.py, services.py etc. And then each of those end up with lots of unrelated things in the same python file, while related stuff is spread over many files. Django apps doesn't really solve this cleanly either.

  • The ORM is really not good in my opinion because it is ActiveRecord'ish and has all its downsides. I wouldn't use Django for any moderately complex domain. But even with simpler CRUD style apps I don't really see the point in it.
  • I seriously don't get why Django ORM is using the Active Record pattern. This is such a stupid footgun that trivially causes horrible performance and BEGS you to cause n+1 problems.

    Never in my life did I have a problem with lazy loading causing unbearable performance until I joined a Python Django team. I really tried to find sympathy for the "dynamically typed" folks (please spare me saying Python is technically statically typed), but coming from writing apps and backends in Java, Swift, C#, Objective-C and PHP, Python with Django was the worst experience bar none.

    I worked on the project for 10 months, could at least refactor the project to something semi-sane where obvious mistakes (which would not be possible in other languages) could not happen. Then along comes a "good Python dev" and threw it all out of the window and start doing SQL queries all over the place (typically 3-6 lines long), remove the domain objects and cause the same problems I started with to begin with. But his approach was saying that the other developers were "not good enough".

    Yeah, have fun with schema changes going forward. Good riddance.

  • I despise django-orm, doctrine is so much better. Like, who thought that using named arguments to do stuff was a proper way ??? `.filter(created_at__gte=XXXXX)` why? The rest of the framework is great but the ORM is definetly its weakest point.
  • If you must use Django, use it through an abstraction layer like this:

    https://adsharma.github.io/django-fquery/

    Your models can be plain old python data classes, declaratively mapped to Django primitives.