Hacker News new | ask | show | jobs
by bbbbzzz1 1169 days ago
I feel like lately js (and more importantly typescript) frameworks have been more popular. If someone were to start a new project today, how does Django standup to the current offerings?
8 comments

I just got into Django after working with Node/Java for years. It's honestly depressing once I realized I have spent so much time building CRUD stuff that would have taken 10x less time with Django.

I haven't built SPAs yet, but I'm looking into trying Unicorn: https://www.django-unicorn.com/

Django's hidden powers are its highly customisable admin UI and ORM. Add to it Django REST framework and you have a solid backend for a wide category of web apps, from the old pre-XMLHttpRequest apps to SPAs. Flask or FastAPI get you going fast, but you quickly realise that you have to write a lot of the code that comes with Django for free.
I personally prefer Django Ninja over DRF for APIs, it's all the good parts of FastAPI mixed with Django.
Honestly, I think the generic and model views are way more impressive than the ORM or the admin. They take away all of the boilerplate usually associated with CRUD apps.
I've used them for quite a while but came back to the old function views. The Generic Views are a mess to understand, the hierarchy tree gets so complicated. See for example : https://ccbv.co.uk/projects/Django/4.1/django.views.generic.... there are 9 classes in the inheritance tree. For every slight change from the default behavior you need to research the documentation, find which method to override…

In the end I have to write a bit more of boilerplate each time (and with tools like copilot it's a non-issue) but it's 10x faster to understand what a view does and how when reading code.

> For every slight change from the default behavior you need to research the documentation, find which method to override…

I just use an IDE which allows me to Ctrl+Click into any symbol and see its implementation and underlying classes (and do so recursively if needed). That saves me from having to lookup the documentation all the time.

It is different. JS is popular because people who write SPAs also want to write backends in the same language.

What I really like about Django and Python ecosystem in general is the kind of stability that it doesn't move too fast and break things, which happens in JS land too often. And Python is a nicer language of the two, for me at least.

But at the end of the day, you can combine both. I work for Baserow now and we combine Nuxt + Django. You can also simplify it to Vue/React + Vite + serve it with Django, use cookies-base auth etc.

Personally I feel like I've unlocked a superpower with this one trick (using rails, but this applies equally to django and similar "old" page-load-based frameworks)

1. build your app in the normal, old way. just doing SSR for showing and editing boring content is so much faster than building it in react.

2. I have a tiny scrap of JS that digs through elements on the page, and if they have a class, creates a React root there and passes in some params. I then wrapped generating those replace-me-with-a-react-root elements in a Rails helper function.

(2 is my "fine I'll do it myself" after Rails 7's new js stuff broke react-rails for me.)

This might be colored by me being a backend dev and data engineer type of person and I have terrifically little patience for writing javascript. But pages where I've followed this "SSR + some React doodads for when you really need special sauce" pattern end up so much easier and faster to write than cramming it all into a huge SPA.

I'm sure if you're building something deeply fancy then doing it all in React makes sense, but I find there's really only a couple pages that actually do end up being 100% react and the rest end up fine just having a text field here or there or a little widget thingy being the React components and the rest just being SSR.

I'm sure this doesn't scale if you're google or something either but even on my most complicated pages this still loads visibly faster than many other sites I use.

I believe this is the way React was originally supposed to be used -- just for a little widgets here and there, not for the entire page/application.
If you use a RDBMS then Django is a very good choice whether you use SPA or not.
I agree, although I really wish Django and sqlAlchemy would have evolved similar methods/APIs. My struggle is flipping between projects that use one or the other and tripping over the syntax.

Edit: grammar

It just works in most cases. It is nice to be within Python's ecosystem as well.

Overall, I've found it great for prototyping up something really quickly. I think this is where the "batteries-included" helps a lot

I feel the opposite. Django is fine, but python ecosystem is the big problem. The lack of true multi threading means for even the simplest of apps you quickly need to have multiple deployments, celery workers etc to handle different kinds of workloads.
You could argue having workers run single threaded code is a lot easier than multithreading, depending on your hiring pool.
It’s boring, well documented, has a ton of modules, extensible, solid, robust, reliable, trustworthy.

I’d pick it for these reasons.

I don't do proper web dev work and tried Django ages ago. So, this is a very narrow opinion. I use mainly flask and firebase these days as a indiehacker.

I don't think currenlty there are any solid alternatives beyond Nestjs+Typescript, ruby on rails and laravel. The sentimemt of their community is that these frameworks are built for web development in mind. While I think for Python based web framework like Django the sentiment is that you are using Python already and here is a web framework written in Python. If you look at some of the Rust based web frameworks you will understand what I am saying. The merit of the framework is the language it was written in. This makes hiring web developers difficult as most candidates will be Python Developer who knows Django and not web developers who knows Python. There are very few people who learned Python to use Django. But everyone learned javascript to use nodejs, or ruby to use ruby on rails.

If I am writing enterprise level where Python is used I will pick one of those 3 frameworks and use a Python based API framework like DRF or FastAPI for building internal APIs.

Python is literally the easiest language to learn. Any web dev can pick it up, and Django is much more productive than NestJS. Rails and Laravel are nice options too. No Rust or Java options come close.
The admin page, DB integration, robust feature set, and insanely good documentation make Django a slam dunk for me. I do understand your sentiment though and for any website that requires a lot of interactivity you need a JS oriented framework like NextJS.

If I need a database and interactivity I pair NextJS with Django Restapi.

> everyone learned javascript to use nodejs

Wut? It's more a case of "everyone learned javascript to do button rollovers in the browser, and then nodejs allowed them to do more".