Hacker News new | ask | show | jobs
by buffalobuffalo 1907 days ago
A couple thoughts on django as a long time user. First, the good:

- Django was the first framework i learned when learning to code. It's documentation was amazing, and it made conceptualizing an MVC framework really easy.

- Django's ORM is phenomenal for managing migrations of a relational database, especially postgres with stuff like jsonb. I've even included it in non-python projects, just to handle table migrations/rollbacks.

- The huge ecosystem is amazing. Great for rapid prototyping. Plugins for all kinds of crazy stuff.

Now the bad:

- In some ways it feels like a relic of an earlier stage of python. It's support of asyncio is spotty at best (running the orm in a thread executor not a good work around).

- It's support for type enforcement with mypy is not great. This is maybe my biggest issue with using it on large collaborative projects.

- It doesn't play nicely with a lot of the rest of the python ecosystem. Want to swap in SQLAlchemy? Sorry, no dice. Want to have nice swagger documentation? Use django rest framework or you're out of luck (i know it can be done, but it's kind of messy). So in short, it's a bit of a monolith.

These days I tend to only use django for it's orm in situations where i want a quick ad hoc database for something, or for rapid prototyping. If I'm going to do a larger project in python, I'd definitely go with FastAPI. But still, gotta appreciate that it's there, and has been reliable/well maintained for more than a decade.

4 comments

>- It doesn't play nicely with a lot of the rest of the python ecosystem. Want to swap in SQLAlchemy? Sorry, no dice.

Being extremely opinionated about stuff like ORM and admin is partly how it developed such a rich ecosystem of plugins. Those plugins exist because they can build upon those foundations.

Flask, by dint of being unopinionated doesn't have solid foundations that its plugins can build upon. This is why you get stuff like quokka (a flask cms plugin built on mongo) while other stuff assumes sqlalchemy and other plugins built plugins for various different storage backends.

I think you could probably abstract away some of the differences between djangoORM and SQLalchemy. Maybe something like a model class that uses sqlchemy for the underlying orm interactions. Not that i really blame them for using their limited dev resources elsewhere.
I've summarized this elsewhere:

Django is really great for writing Django apps. It's not great for writing other kinds of apps.

If your app is a CRUD interface over a relational DB, it's awesome and I mean that sincerely. I'll happily reach for it instead of reinventing that nicely crafted wheel.

If your app isn't -- say, it's backed with noSQL or maybe is a frontend over a bunch of backend API calls such that you're not using its ORM or its permission model -- then it feels like a box of pain.

How productive are you with FastAPI compared to Django? I’m thinking of things like forms, error handling and all the other extra stuff that comes with decoupling the frontend and backend.
The main thing I would wonder about is if there's a good auth plugin for FastAPI.

I am not a huge fan of Django, but if you have already chosen Python, it is really hard to argue with having good, battle-tested auth system out of the box.

The other side of the coin is that django's auth system is pretty rigid. Adding additional fields to the user object is clunky, and trying to do an unusual auth flow can be downright ugly. Dealing with that a few times can leave you a lot more open to designing your own and/or patching together other libraries. At least, that's how it went for me a few years ago.
Django allauth handles 90% of auth needs. Adding fields to user is easy if you set it up correctly
Not nearly as productive. That's why django is definitely a better choice for rapid prototyping. But if I'm working on a larger project that I'm hoping to maintain for years, up-front productivity usually takes a back seat to maintainability/scalability/extensibility. For those, I'd go with FastApi
You can absolutely use sqlalchemy