38 comments

[ 3.5 ms ] story [ 86.8 ms ] thread
Given new entrants into the backend space, like Supabase (for a Firebase-like open source alternative), Hasura (open source GraphQL on Postgres), etc, how viable is Django and similar technologies like Rails these days? It seems like the former are PaaS which you can simply drop into your app but the latter are more so full on backends that let you control everything.
I run Hasura and Django. Django really excels at migrations and Django is nice to have a place to write admin views. For example a way to generate a report and manipulate the data in a way that is easy to use. No way to do that in Hasura.
>Given new entrants into the backend space, like Supabase (for a Firebase-like open source alternative), Hasura (open source GraphQL on Postgres), etc, how viable is Django and similar technologies like Rails these days? It seems like the former are PaaS which you can simply drop into your app but the latter are more so full on backends that let you control everything.

How viable? More viable than the newer systems you mentioned, clearly.

Backends aren’t just npm packages you throw away with each new project or iteration. Rails has an amazing ecosystem around it and tons of competent developers that can write maintainable code and others that can maintain it. Same with Django. You might be surprised that PHP is still extremely popular.
What might surprise him/her even more is that PHP is actually better than js/react at anything web related. Symfony and Laravel are amazing frameworks. You get frontend scaffolding and admin generation,fast templating languages, authentication, authorization, databases, great tooling. On top of that PHP 8.0 improved the type system and these frameworks are quickly adapting to use types everywhere.

When it comes to web applications tho, Django is not as pollished as Laravel/Symfony. There is no webpack integration (or any other npm frontend tool). built-in authentication is very basic, hosting is a pain.

The thing is a haven't written a single line of code in Django, but modern PHP and it's ecosystem looks more fun from a front-end, JS developer's perspective

How can you say Django is not as polished when you haven't even used it?

Laravel is a great framework, but the tooling in PHP is amateur hour by comparison. The app ecosystem in Django is only comparable to Rails'.

> but the tooling in PHP is amateur hour by comparison

Looks like maybe the ignorance goes both ways? People really underestimate the size and maturity of the PHP web development ecosystem and it's professional community, and there's no shortage of tooling to build and support apps on the language.

Django: 34,019, Laravel: 26,881, Rails: 9,300

https://github.com/topics/django

https://github.com/topics/laravel

https://github.com/topics/rails

and Symfony: 25,800

https://github.com/symfony/symfony

Modern PHP ecosystem is a shadow of their former self, in a positive way.

Composer shored up package management. Laravel and Symfony offer robust framework ecosystems. PHP 7 bridged the performance gap with HHVM. Libraries for a wide-range of critical infrastructure services from databases (Postgres, MySQL, Elasticache, Redis) to messaging systems (AMQP, Kafka, ) to monitoring and observability (New Relic/DataDog, Prometheus, Sentry). Cloud support is ubiquitous.

Even the top packages are pedestrian things like logging, event dispatching, sub-process management, and testing.

But PHP has a Microsoft-level of baggage, and those bridges can't be unburned.

it's been awhile so the details are fuzzy but the Django shop I worked at had a repository of their like master app template, customized to rapidly prototype the kinds of apps the company built. it was pretty quick to get going on a new project but it was a bit of a kitchen-sink approach that pulled in quite a bit of cruft you might not need, but it was alright for our purposes. I assume other places do something similar.
I do a template type of project structure and the rest are shared libs or git modules.

It's pretty fast to prototype and then cut stuff you don't need.

The vast majority of those frameworks will not make it past two or three years until maintainers give up or the usebase switches to the next shiny thing.

Rails and Django are the pieces of web tech most likely to stay in the game.

At least initially a lot of the GraphQL implementations resulted in slower apps, way more time to get going etc. This may have been because they seemed to tilt towards NoSQL backends, so that may be a big help if that is changing. I always did use views in PostgreSQL. Not graphQL, but you can simplify your request cycle using that if needed.
I don’t get why there is so much negativity on Django when Instagram and other large websites still use it.

I used it a few years ago for a startup and I liked it. It also has a user management system built in also .

Where do you see negativity? I've been using it professionally for over a decade, and can highly recommend it. Very mature, polished, fully featured, reasonably performant, well documented and a pleasure to use. A real productivity boost. It's the most widely used web application framework in the python world, which happens to be my preferred programming language.
The ORM is the only weak point, the rest is widely considered stable and of quality.
What's weak about the ORM? I've been working with Django for the last year or so and find the ORM great, but I don't have much experiences with other ORMs to compare to.
It lacks a unit of work system to allow precise control over loading and saving data. It also lacks an abstraction for composing arbitrary SQL queries out of components. It’s sometimes very difficult to predict the number of queries that will be emitted.

It’s a reasonable ORM, but doesn’t compare to SQLAlchemy.

I strongly agree with this; while the ORM is great for simple/medium complexity use-cases, it really lacks the flexibility to extend into more complex domains. SQLAlchemy can hit all the Django ORM's use-cases, and also can be used for a bunch of designs that the Django ORM simply cannot support.

A dirty-tracking mode would be great. This is really useful if you want to have code that builds up a list of sub-objects, and then _maybe_ commits them, but maybe rolls back after creating most of the Python objects. The naive Python you want to write is `for i in range(10): foo.bars.add(Bar(i))` which in the Django ORM triggers a DB write for each bar, even if you error out on the 10th Bar.

As you say, another area where the ORM can bite you is the always-on foreign-key-traversal logic. So if you have loaded model foo, then accessing foo.bar will trigger a SQL query under the covers, if you didn't select_related/prefetch_related properly. This is great for simple use-cases and exploratory coding, but can make it very easy to write code with horrendous performance. Naively-coded views often have hundreds of DB lookups and it's hard to track down where these are coming from when the app is complex and especially when you've got _some_ *_related in place, but you're missing a prefetch somewhere.

Django's ORM is pretty incredible actually. I've been able to do some very advanced queries including window functions, several subqueries, even recursive CTEs...
What makes you think it's the weak point? Imo the ORM is easily the best bit.

The request-handling and template rendering is in my mind the weakpoint.

I agree with this, I've been using Django for more than a couple of years. The built-in admin interface is a blessing, the ORM is good enough and unless you are handling very huge loads it doesn't matter if it doesn't always generate the most efficient queries (in more than 5 years I've never run into any issues with that). The almost but not exactly MVC pattern that also let's you mix both class and function based views coupled with a very limited template system is a curse. I would have preferred one way to do things(TM) but the Django approach let's you badly do a hundred and more different ways if you aren't very experienced with it (and even if you are you need a lot of discipline to do things properly, and even if you have discipline sometimes Django doesn't have a feature you need so you implement your own and then a major release comes and now it has its own incompatible way of doing the same thing). I still wouldn't change Django for anything else, I'm sure I wouldn't have a job anymore if it weren't for how fast and easily I can implement things with it (management is an absolute hell here and changes how everything is done every couple of months until management itself gets fired and replaced every year or two).
Instagram started with Django but today it "uses django" only with the air quotes. Listen to the interview with Carl Meyer https://djangochat.com/episodes/django-instagram-carl-meyer
Here's the relevant excerpt, lightly edited for clarity and accuracy:

> I mean, Instagram server is still a big Python codebase. It's Django at the core, I mean, it still runs through the Django request handling stack, and the middleware and views and URL routing, all of that is still Django. It looks familiar to any Django developer. Just very big, lots of views, lots of URLs, lots of code. There's a lot of, I mean, obviously, the ORM we don't use anymore, the admin is very much based on the ORM, so that's not in use anymore. And there's a lot of components, where Django provides kind of pluggable back ends, like sessions and authentication, and for all of that stuff, we've essentially rewritten the entire system. But we're actually still using the sort of Django API for those things, because it's pluggable. So I would call that a success story, I mean, in that we've been able to very smoothly migrate away from the components that that no longer worked at our scale, in many cases without even having to change the client code touching those subsystems because Django provides this ability to swap out the back end. So yeah, and you know, the Django core requests support that we still use, we're 100% async now, so already a few years ago, we kind of forked and modified a bunch of that to support async, or concurrent handling of multiple requests using async IO. So there have been some changes.

- an old fork that has a custom async support - no use of ORM - no use of admin - replaced sessions - replaced auth

I would say it is a Django success story but given how much has been replaced it sounds more like a Python success story to me.

It's a "let the framework help you write a sensibly structured code base so you can make good decisions ongoing more easily" success story really.
Kudos to everyone that contributed to Django in any way.

Been using it for more than a decade and never it has disappointed me.

Every release comes with excellent features and polishes.

Everything in Django is well mature, properly maintained and built for maximum productivity and maintainability.

One of the best thing about Django is, it's never gets involved with bubble type technologies until proven reliable and useful.

Either be it async, websocket, NoSQL, fancy SPA, AMP, or any specific frontend framework integration.

So much of this. I have seen so many developers switching between frameworks every two or three years, wasting away substantial accumulated knowledge and bags of tricks, the kind that allow you to make a living as a consultant because you can crank out CRUDs and REST endpoints like it's nobody's business.

Some parts of the framework feel a little long in the tooth. The admin could use a rewrite with CBVs; the forms API just doesn't look so good compared to serialization abstractions in Rest frameworks nowadays.

Still, it is a weapon, combined with Postgres, container-based deployments and a half dozen Django apps, there's few frameworks that come even close in terms of productivity and polish.

It's a nice combo of pretty stable, very productive, good technology. The postgresql integration is wonderful, so I like the database choice and they've had good support for postgresql for a while (a lot of other frameworks really were MySQL focused). Mix in container based deploys - great!
Exactly.

I used pretty much many framework before settling on Django and polishing my knowledge and skills on it.

Some places of Django could annoy me a bit, for instance Admin customization, but I got to conclusion that it's impossible to make Django customizable to every needs. The best would be create an admin dashboard for your own stuff. Charts, reporting, backoffice type are. Although it's possible to do so with current admin, but it's get annoying and after a while I see it be much better served if my requirements get created separately without poking around the admin so much. I usually create a separate app then include all the business requirements that don't fit in admin.

Probably admin could expose a REST API? meh!

Been a very long time that haven't worked with Forms, but compared with what comes out from DRF serializer etc, indeed would need some love. However, it's been years since majority of apps are built by frontend frameworks and using Django via DRF.

The integration that comes with PostgreSQL and everything around Django ecosystem is mad productive.

It takes a very short time to prototype and containerize the whole thing and have it on production.

Fortunately or unfortunately, since I got comfortable with Django, I compare everything with it and it's really really really hard to swap it with something else.

I like Django a lot and use it for my projects and with clients.

> One of the best thing about Django is, it's never gets involved with bubble type technologies until proven reliable and useful.

Django has also chosen not to get involved in tech that *has* been proven reliable and useful.

For example moving to incorporate a formal API library like DRF years ago. It also has not indicated plans to adopt a type-based API library like FastAPI or Ninja.

Often this idea of supporting REST API building as a battery of Django is used as a cudgel against modern front-end frameworks. The comments are generally aimed at React, but broadly anything in Javascript that requires an API.

However, doing so has also been expense of making Django a first choice for microservices and ignores the important role of serving mobile app clients.

Django has also been slow to discard technology that is no longer reliable or useful. For example, jQuery is still endemic in the ecosystem.

I'm all for stability--I've invested a lot of time in Django and it is very productive. However, the biggest threat to this framework is the effusive self-praise for this attribute.

People would do well to remember that Django displaced Drupal because Django was iterating rapidly even though it made upgrades very challenging at times.

FastAPI and now SQLModel are showing how valuable adoption and use of Python's type system can be.

There is no reason why a new Python-based framework (apart from Flask) could not unseat Django as the framework of choice. It wouldn't even endanger Django. People still build using Drupal today.

why would you want a full framework with a admin back end for a microservice?
In fairness, you can disable the admin service if you want, then it just makes Django a big fat bloaty library.

But more to the point, I feel like DRF is kind and of a weird solution anyway, like the request object is different from Django, it doesn't support schema generation without some third party libraries...

Frankly, FastAPI with an orm sounds like the ultimate python microservice framework, anyway. Pgcli works as an admin interface in a pinch.

Agree. What advantage does FastAPI have over Starlette on it's own?

I've written my latest api w/Starlette and found it to be excellent.

Very comfortable pydantic integration. This gives you Swagger docs and type checking for free.

I've never actually used starlette directly, but it doesn't sound very ergonomic

The batteries included with it.

A consistent DB interface, ORM and migration system (independent of the underlying DB), same for cache (similarly you can swap Redis for Memcache and your code doesn't have to change), same for e-mails (swapping e-mail providers is a matter of writing a new backend, application code doesn't change), etc.

Sure, you could do all this with Flask and SQLAlchemy, but Flask and these minimalist frameworks always feel like they lack structure and good conventions which means every project does its own thing. In Flask & SQLAlchemy I still don't have a good way of organizing my application and model classes considering they have to inherit from an instantiated DB connection object. I'm sure there's a way and I haven't researched enough, but why bother when Django solves this problem with "one true way" that everyone conforms to?

Also keep in mind that despite Django having many features, only those that you actually use will be invoked; you can slim it down further by removing some middleware (hooks that run upon every HTTP request lifecycle) but even in its default configuration it's pretty light - for example the admin is not loaded nor evaluated unless you actually assign it to a URL route and a request hits it. Same for the HTML templating support - unless you actually render a template from a view it's as if it didn't exist - you only waste some disk space but there's no runtime performance hit.

Kudos for linking the signing public key in the release announcement.

I see many announcements where it is difficult to find.

After the solarwinds breach I started an open source project to replace solarwinds. I used django and it's working great.

Anyone have experience upgrading django? Does it go well?