What I love about Django

(buttondown.com)

57 points | by j4mie 2 hours ago

16 comments

  • matsemann 33 minutes ago
    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.

    • DarkNova6 14 minutes ago
      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.

  • saaspirant 4 minutes ago
    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.

  • sinpif 2 minutes ago
    Migration churn adds up over the years but overall it's nice and site-specific code is usually so small it fits very nice in LLM context.. easy to work with.
  • whateverboat 5 minutes ago
    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

    • vb-8448 3 minutes ago
      what's wrong nowadays w/ django?
  • stuaxo 52 minutes ago
    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.

  • JodieBenitez 1 hour ago
    Most loved feature, for me: No dramatic changes, just sane and careful evolution.
  • harrouet 20 minutes ago
    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.

  • tinodb 21 minutes ago
    > 3. Actions

    It is somewhat explained as a convention or something built-in, but I can't find much about it elsewhere. Is it the author's own convention or am I missing something?

  • Klonoar 27 minutes ago
    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.

  • 0x4d4c 39 minutes 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.

  • tonyedgecombe 58 minutes ago
    I haven’t used Django for a long time but when I did I found it one of the best documented projects out there.
  • Maxion 1 hour ago
    Django is boring, which is why it works well. Use the ORM together with DRF serializers and an OpenApi generator and you can create TS types and TS client directly from your API.

    Works incredibly well almost straight out of the box for even quite large applications. Once you start to grow out of it, it's easy to bypass the ORM and write raw sql queries.

    You also won't be re-writing your backend every few years, the cost of which techbros often ignore.

    • aitchnyu 39 minutes ago
      If the DRF stack seamless like Ninja now?
    • angusj1 22 minutes ago
      [flagged]
  • stavros 1 hour ago
    I agree, Django is just fantastic. Nothing is perfect, but Django is just really well-designed, with components that fit together naturally into a balanced whole.
    • weatherlite 1 hour ago
      Just wanted to say I saw your last stand up , you're hilarious!
      • stavros 1 hour ago
        Thanks, my love of comedy is only surpassed by my love of Django.
        • weatherlite 1 hour ago
          Naa you lie you love twinkies more than Django
  • alexbelyanin 15 minutes ago
    [flagged]
  • songhonglei1985 29 minutes ago
    [flagged]
  • cryo32 52 minutes ago
    My favourite part of Django is it's not Rails :)
    • 0x4d4c 42 minutes ago
      Why is that? What's wrong with Rails?
      • panzerboy 38 minutes ago
        It's made by DHH.
        • 0x4d4c 33 minutes ago
          And great bunch of other, awesome people.

          I can take an argument of not buying a Tesla in order to avoid supporting Elons financial empire, but not using Rails because DHH made it is really hard to comprehend.

          • owebmaster 16 minutes ago
            Why is it hard? Elon got all the power he wanted. Not giving DHH the same free passes Elon got is a very reasonable take.
        • BoumTAC 34 minutes ago
          The DHH hate is absolutely crazy on HN.

          I don't understand how people can be so out of touch.

          • panzerboy 5 minutes ago
            I don't hate the guy (I don't know him personally so I cannot hate him), I just disagree with his opinions and I personally don't want to use anything that he makes or endorses. Easy as that.

            I know that there are other people contributing to Rails, and that's their choice. Other people stopped contributing once DHH showed his true nature.

          • owebmaster 15 minutes ago
            Do you think DHH is out of touch too?