(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=38517099

然而,对于移动部件较少的简单应用程序,Flask 或 Bottle 等替代框架可能会提供更大的灵活性和更容易的开发。 最终,框架的选择取决于每个项目的具体要求和约束,而不是遵循特定的趋势或教条。

相关文章

原文
Hacker News new | past | comments | ask | show | jobs | submit login
Django 5.0 (djangoproject.com)
511 points by sarahboyce 17 hours ago | hide | past | favorite | 185 comments










Django made me fall in love with programming 13 years ago, and since then it has always had a special place in my heart.

I’m revisiting a business idea I was working on for a couple years, before I sought and found employment in the industry (where I used Java for a couple years, then Elixir for a couple more). My project was built with Django and Django REST Framework, and Ember on the client-side. 6 years later, the Django side needed minimal changes and is up and running (I jumped all the way from 1.11 to 5.0 beta).

Meanwhile, the Ember part is “lost in time… like tears in rain”. I tried everything, downloading older versions of Node and even the now-deprecated Bower. I don’t fault Ember (which is actually the most stable of the major JS client frameworks). But the JS (especially Node) ecosystem is beyond redemption in my eyes.

For my rewrite of the client, I’m going to skip the drama and just use htmx. Render Django templates server-side, include a single JS script, thrown in some HTML attributes, distinguish between full page requests vs. requests for a partial with updated data, and call it a day. No TypeScript, no Webpack, none of that nonsense. If I need special interactivity I can throw in some hyperscript.

At work I’ve used Elixir/Phoenix/LiveView and it’s revolutionary, truly awesome tech. But to get to market I would rather not have to customize an auth system and build a decent admin interface myself (I tried Ash; its auth and admin are not mature enough to be compared to what “just works” with Django). Yeah, it won’t be as scalable as a Phoenix app, but to me, Django seems like the most clean and rapid way to get to a point where you’ll actually need scalability.



> 6 years later, the Django side needed minimal changes and is up and running (I jumped all the way from 1.11 to 5.0 beta).

I've been using Django since before 1.0, and the upgrade story has been nothing short of fantastic for something that's been around this long. But still, YMMV!

Depending on how ancient a project you run into, it definitely can be a major pain, even with the original authors' best intentions. For example, Django didn't have its own DB migration system until 1.7 (relying on third party solutions); this means you also have to adjust the deployment procedure, which means recreating an ancient setup (ideally in an easily repeatable fashion, because you're going to be trying that migration at least a dozen times).

The builtin admin system is also a pretty decent CMS on its own, but falls short as you run into slightly more complex use cases (such as basically anything that requires even a single line of JS). The docs will encourage you to copy and override the builtin templates; this often becomes a pain point during upgrades. It's wise to get off the builtin admin system as your project grows.



> The builtin admin system is also a pretty decent CMS on its own (...) It's wise to get off the builtin admin system as your project grows.

And go to another superbly robust and easy to use actual CMS: wagtail.



Wagtail is absolutely fantastic for content-heavy websites, like blogs, journals, catalogues, archives, venues (event schedules), also everything that deals with loosely-structured data. It's much less useful as a general purpose CRUD framework - it's too focused on "content", it wouldn't spark joy.

Also it's been a few years since I've last used it, but the overwhelming dominance of deeply nested JSON fields makes ordinary DB migrations unnecessarily interesting.



> it's too focused on "content".

Isn't that a good thing for a Content Management System?

I am not sure I understand what you think could be done to either the admin (or wagtail) to make them "CRUD frameworks".



The jump from Django to wagtail was like the jump to Django in the first place, I wish more projects I get to work on were based on it.


FWIW I've also had the same experience; the last version of Django where upgrading took a non-trivial amount of time was 1.8, because it changed how isolation is enforced within test cases. Since then it's rarely taken more than an hour or two, regardless of how big the codebase is.




I'm with you on this, Django + HTMX + Vanilla JS (where needed) just works which is a beautiful thing.

Is building out the UI clunkier with Django templates than with JSX? Absolutely.

But not having to worry about both server and client side state is such a time saver and you know it is going to continue to work.

For the past few years I've been using Go (using Gin) in place of Django, and it works nicely and is quite a bit faster. However, recently I've been toying around with Django again, thinking about making it my default for new projects because it really does take care of so much that you'd otherwise have to deal with yourself.



An approach I've done in the past for projects that are publicly API-based:

Django handles the database migrations and user accounts/models/etc - and you get the useful admin to boot, which is just incredible if you ever need to open up the data layer to someone else.

Then just write the API interface in Go/Rust/your language of choice. It decouples the DB modeling from the API layer, but in practice... I've just not run into significant issues with it. I'm sure it could be an issue though, so YMMV.



It's not a bad idea, but the tradeoff is usually you'll have to define your models twice. For whatever reason, that tends to happen anyway, so not that big a drawback in practice.


Eh, in my case I prefer writing raw SQL for the API side of things - it's more apparent what's going on in code that I actually tend to wind up debugging down the road. As a result I don't really feel like I'm writing models twice - I model then code, then just read it directly, if that makes sense.

You are ultimately still right, I think - just a personal nuance I guess.



As a full-time Node.js dev, I agree with your decision! Too much time is wasted on compatibility problems. I'd almost say it was easier when we just had browsers to deal with. At least you could just drop in jQuery and call it a day.


Yes, jQuery is often derided as outdated, but it worked quite well for a very long time, with minimal hassle for developers. In fact, I was working full-time on static Elixir/Phoenix pages with jQuery sprinkled on top as late as 2022… it felt a bit clunky but it worked as advertised and wasn’t frustrating in any significant way.


I still use JQuery because of all the syntactic sugar and shortcuts.


Me too, I prefer the API.

At the end of the day I’m delivering reliable and productive solutions for my clients, and they don’t care what the tech is.

However the Django API, GraphQL with React front end stack I’ve inherited is an frustratingly flakey to use and a nightmare to develop :-/

It’s so bad I’m regretting all my life choices that led me to this point LOL



I’m curious to hear what are some of the most frustrating points developing with Django, React, and GraphQL.


I absolutely agree. Recently I had to work on a complex client app, and I could simply not believe the amount of trouble you have to go through when you want to increment the version number of things like React, MUI, webpack, TS by.. one!


> want to increment the version number of things like React, MUI, webpack, TS by.. one!

To be fair, in semver that means a breaking change of some sort.



> I’m going to skip the drama and just use htmx for the client-side. Render Django templates server-side, include a single JS script, thrown in some HTML attributes, distinguish between full page requests vs. requests for a partial with updated data, and call it a day.

More of a side comment, but I'm skeptical of the way HTMX encourages partial renders like this. It feels like a premature optimization that adds more complexity on the back end. `hx-select` takes care of it, but to me it feels like it should be the default (it's what Unpoly does).



There is a package, https://github.com/carltongibson/django-template-partials, that is basically like server-side hx-select, when there is some performance concern. Overall, I agree with you though, hx-select is going to be fine most the time.


Thanks for sharing that! I also just finished watching Carlton’s talk from DjangoCon EU (linked in the repo) and it is gold: https://youtu.be/_3oGI4RC52s


There is a header that htmx injects to indicate you want a partial render, and it’s really not that hard to add an if on the server-side to check for it. A larger codebase would probably break templates up anyway for maintainability, so it’s just a tiny amount of extra work if you want to reduce the amount of HTML being sent over the wire and swapped in.


Django and django-unicorn is really nice. It feels like meteorjs but for Django, extremely productive. I've been working with the creator closely and he's awesome.


django-unicorn is really impressive! So glad to see people pushing back on all the gunk inherent in webdev still.


I haven't used Elixir yet and mostly using flask in Python for work but I started with Django (and still think it's better than flask for most apps). If stuff like https://github.com/aesmail/kaffy (first thing I've found on google, never heard of it before) is on par with the Django admin, would you still use Django or Elixir and never look back?


I don’t know if I would “never look back” to Django (I’m a sentimental person). But admin is one aspect, the other big one is auth. I also like DTL better than EEx/HEEx. And all the pieces of Django just fit together really nicely; where Ecto happens to be the preferred way to interact with a database from Elixir, and Phoenix happens to be the preferred way to build Web apps using Elixir, (maybe with Ash layered on top), they weren’t designed by the same people, so you have packages like ecto_phoenix, ash_phoenix, etc. to make them all play together in an elegant way.

I will admit, Elixir and Phoenix have better real-time and scalability stories.

If I had a choice I would probably prefer Elixir/Phoenix/LiveView when joining an org to work on an established codebase that may have actual scalability needs and concerns. But I would probably prefer Django when starting from scratch.



Totally agree, but is Ember truly the most stable? This is pretty much my only criteria for JS at this point.


If you want a heavyweight JS framework, Ember is the most stable and best supported. I enjoyed Ember when I used it in the 2015-2017 time frame.

But I’m abandoning the heavy JS paradigm in favor of htmx. Aside from the fact that I don’t want to duplicate routing and data validation across client and server, htmx is intentionally a single JS file with no build step, so in theory it should run fine as long as browsers maintain backward compatibility.



Fwiw trying to get an old ember app running was an absolute nightmare. On top of that it is way too heavy for my liking. Pretty much polar opposite of jquery.


i've been using django + htmx and vanilla js where needed. it's great!

my biggest beef with it is code organization, which will only get better with more experience. and it's a side project so it doesn't matter. i do worry about using it on a team because i could this stack getting messy if not done the right way.



Release notes: https://docs.djangoproject.com/en/5.0/releases/5.0/

Related Community Resources

* New goodies in Django 5.0 [blog]: https://fly.io/django-beats/new-goodies-in-django-50/

* What's new in Django 5.0 [video]: https://youtu.be/lPl5Q5gv9G8?feature=shared

* Database generated columns⁽¹⁾: Django & SQLite [blog]: https://www.paulox.net/2023/11/07/database-generated-columns...

* Database generated columns⁽²⁾: Django & PostgreSQL [blog]: https://www.paulox.net/2023/11/24/database-generated-columns...

* Building a Bootstrap styled form in vanilla Django [blog]: https://smithdc.uk/blog/2023/bootstrap_form_in_vanilla_djang...



My app is a Django backend and a Vue frontend. There are large swathes of Django that I ignore, but to me the core of Django — its ORM, routing and middleware system, and admin interface — are worth their weight in gold. The migration from DRF to Django-Ninja (which is, roughly, FastAPI + Django) has also been a great improvement in terms of productivity and performance.

Not a lot of whizbang features in 5.0, but GeneratedField looks like a very nice addition, and reason enough to migrate.



Coming from iOS/macOS background, I've kinda enjoyed Django with its all time classics (forms, templates, etc.) + HTMX.

Admin interface was extremely helpful, when we are trying to validate business idea.



GeneratedField looks interesting, but I'm not _really_ sure what gains I get over just calling annotate() on my queryset with some computed fields. At least on the backends where the computed GeneratedField isn't stored.


It's easier to re-use if you need the same generated field in multiple places.


I've been in the habit of replacing the default manager for my model with one with an annotated query set. that way, any Model.objects.all() call will have the computed fields.

I find this pretty easy to get used to and re-use. though I do admit I like them defined as actual model-fields with verbose names etc...



Actually having the derived data in the database would be helpful for simplifying something like a website search implementation. I know I could have used it last month!


It's a generated column in the database, vs. annotate is just a python alias for something you're selecting in the query.


Any resources/examples you'd recommend for a Vue frontend w/django? I've been pretty firmly in backend land for a while and would to experiment with the other half of the puzzle!


I'll preface all of this with a couple esoteric design goals that I had in mind:

1. I actually _want_ an SPA. You might not need an SPA, if you don't need one then Vue/React/etc are overkill, etc.

2. I want to power as much of the SPA as I can using the same REST API as my core product, both for dogfooding reasons and for consolidation. Many people might argue that this is a bad idea.

---

With that in mind, some specific packages that I highly recommend:

1. Django-vite (https://github.com/MrBin99/django-vite). This makes it very easy to serve an SPA from the actual django response/request model

2. Some sort of way to get type information (if you're using TypeScript) into the frontend. I use a frankensteined system of the OpenAPI spec that django-ninja generates + openapi-typescript (https://github.com/drwpow/openapi-typescript). This means when I add, say, a new field to a response in Django, I immediately get typechecking for it in Vue — which has been _tremendously_ useful.

3. Django-typescript-routes (a package I extracted and open-sourced!: https://github.com/buttondown-email/django-typescript-routes) which gives your front-end routing information based on the Django router.



If you really need VueJs in the frontend, consider, that you can simple serve the VueJs on any page where it is actually needed. VueJs does not necessarily mean you must create a SPA. VueJs can be delivered like any other script and this is often the easiest way without having to commit to build a full blown SPA.


How was the effort to migrate from DRF to Django-Ninja? I saw Django-Ninja mentioned in another post and am thinking of switching one of my projects over from DRF. After skimming their documentation, it looks very pleasant and simple and perfect for my use case.


Going from 0 → 1 migrated route was "medium difficulty", I'd say — there was a non-trivial amount of scaffolding I had to build out around auth, error codes, and so on, and django-ninja's docs are still a little lackluster when it comes to edge cases.

Once I had that one migrated route, though, the rest were very simple. (And I am very happy with the migration overall!)



I've had that on my list to try out for a while now. FastAPI is a joy, having generated OpenAPI is a must, so Ninja sounds good.

I've had quite enough of DRF's tower of mixins and rails like magic. It always sucks up development time and fails too easily.



Mine too - Vue and django, and the django rest framework, it’s super productive - no writing all the crud views manually for the hundreds of models I have, the django admin interface is very helpful like you say, and backend is running (a very highly customized) django celery mix,

Django + REST framework takes a little more to learn than something like FastAPI, but once you understand how all the middleware, permission and query classes work, you can be hyper productive



Agreed, the admin makes development so much easier, being able to easily enter and view your data.


Django is such a lovely framework I can't speak higher praises of it. I'm blessed to still be able to use it in my day to day work. It's maybe not the most flashy framework out there these days but Django and Rails are really the Toyota Corollas and Honda Civics of the web dev world that often go so underappreciated for their unfussy reliability. :)


I’d say they’re the Lexuses of the web dev world. Very nicely appointed and rock-solid, just not very sexy.


Sadly I don't use Django anymore at work but it still has a special place in my heart. The ORM model is the best I've ever worked with and any other always feels clunky with sharp edges to cut you when you hold it wrong.

In recent years Django had multiple major releases, I still remember it as being in 1.x forever. Does somebody know what changed within the Django Community that they break backward compatibility more often?



The release process is time-based as to roughly every 8 months[1] with X.0, X.1, and X.2 (LTS). This is mostly to communicate which release has long term support.

The deprecation policy[2] is taken very seriously and Django doesn't opt to break things if it can.

Recently there was a very interesting discussion[3] between the Fellows as to whether the version numbering is confusing as this doesn't follow the same pattern as other libraries.

1: https://docs.djangoproject.com/en/dev/internals/release-proc...

2: https://docs.djangoproject.com/en/dev/internals/release-proc...

3: https://fosstodon.org/@carlton/111300877531721385



> The ORM model is the best I've ever worked with and any other always feels clunky with sharp edges to cut you when you hold it wrong.

Idk. I have to grant that Django ORM likes to make your life easy, but lazy loading on property calls is a dark pit full of shap punji sticks. Just overlook one instance where this is happening in a loop and say goodbye to performance and hello to timeouts left and right...



Simple middleware can warn you about lazy loading/N+1 queries. Most of the time people just forget it happens.

Try using: https://github.com/har777/pellet

Disclaimer: I built it :p

You can easily see N+1 queries on the console itself or write a callback function to track such issues on your monitoring stack of choice on production.



I did this by adding every SQL query to a new log file (only active in development), then tailing it while developing. Not only is 1+N very visible as a long string of the same query over and over, it also lets you see in real time when there's a long pause from a query taking longer than expected.

Also we often had something that was more like 1+3N, basically a 1+N problem but it was looping through the same 3 queries over and over.



FWIW Sentry has recently (within the last year or so) rolled out support for N+1 monitoring as well.


That looks handy, thanks for sharing! I used to use some other n+1 logger, but yours actual shows the query which is more useful.


Have a pitch on what differentiates this from django-toolbar? Just the focus on query count monitoring?


Yeah the query count monitoring is the main focus as N+1 queries are super common in Django.

I don't really have a pitch but here is why this was made:

1. we had a production DRF app with ~1000 endpoints but the react app consuming it was dead slow because the api's had slowed down massively.

2. we knew N+1 was a big problem but the codebase was large and we didn't even know where to start.

3. we enabled this middleware on production and added a small callback function to write endpoint=>query_count, endpoint=>query_time metrics to datadog.

4. once this was done it was quite trivial to find the hot endpoints sorted by num of queries and total time spent on queries.

5. pick the most hot endpoint with large number of queries, enable debug mode locally, fix N+1 code, add assertNumQueries assertions to integration tests to make sure this doesn't happen again and push to prod.

6. monitor production metrics dashboard just to double check.

7. rinse and repeat.

For me this ability to continuously run on prod -> find issues and send to your monitoring stack -> alert -> fix locally workflow is the main selling point. Or of course you can just have it running locally on debug mode and check your console before pushing your changes but sometimes its just hard to expect that from every single engineer at your company. Then again your local data might not cause an issue so production N+1 monitoring is always nice.



Monitoring production is the piece I was missing. Was thinking of it as strictly for development.

Unless it adds a bunch of overhead, seems like a no-brainer to enable.



It only adds like ~5ms. Unless you have `query_level_metrics_enabled` as True which takes more time. I didn't find that particularly useful on prod and instead just used it locally when fixing stuff. Depends on what data you need populated in your callback function on prod.

The header feature can also be useful. If you have a client on-call who's complaining about super slow page loads. Just check their network tab and see which response has a query count/time header which seems unnatural.



I think Django's ORM is a product of its time, when limitations about the expressibility of the "active record" concept were not fully understood.

I like to describe it as Django's ORM will satisfy 80% of your needs immediately, 90% if you invest and sweat, 95% if you're quite knowledgeable in the underlying SQL. But there are still some rather common query shapes that are inexpressible or terribly awkward with Django's ORM.

SQLAlchemy on the other hand never tries to hide its complexity (although to be fair they've become much better at communicating it in 2.0). On Day 1 you'll know maybe 20% of what you need to. You might not even have a working application until the end of week 1. But at the end of, idk, month 6? You're a wizard.

The long-term value ceiling of SQLAlchemy/Alembic is higher than Django's, but Django compensates for it with their comparatively richer plugin ecosystem, so it's not so easy to compare the two.



Non-performant code is going to eventually slip into any codebase. The trick is to monitor for when performance falls to an unacceptable level. Not toss all ORMs because some minority of generated queries are problematic.

If maximum performance, 100% of the time was the end-goal, I would not be writing Python.



The python team I joined grew their codebase from a thin data access layer into a full blown application. Staff was full of data guys and had no idea about application engineering, but lots of opinions. The client was another company who intended the product as heart of their digital transformation.

Guess who had to refactor this mess and steer away from catastrophy.

I’m haunted to this day.



That general story can happen with any tech stack.

POC whipped together without good architecture. Having proven itself, usage increases until the application starts to burst at the seams. Program must be redesigned, avoiding performance gotchas.

I still think Django + the ORM give you a lot of runway before performance should be a concern.



> Just overlook one instance where this is happening in a loop and say goodbye to performance and hello to timeouts left and right...

FWIW they do give you assertNumQueries in the testing tools, which makes it relatively easy to catch this as long as you have tests.



I sort of said this elsewhere. Others are saying "that's just what happens" and "well, Python?" but it doesn't just happen, and slow database queries are nothing to do with the application language. The problem is Django ORM, like Ruby on Rails, uses the Active Record pattern. Alternate ORMs, such as SQLAlchemy or Hibernate, uses Data Mapper pattern, which avoids the pitfalls of Active Record.


We can have 1+N queries in any language even without an ORM. Maybe an ORM facilitates mistakes because it hides joins but lack of experience is lack of experience. Some naive bad pseudocode:

  for book in select * from books:
    author = select * from authors
             where id == book.id
    print book.title author.name
In the real world that nested select could be hidden many levels down in method or function calls or even in code run from the templating language. Example: Django templatetags can query the database from the HTML template and any framework or non framework I worked with can do that too.


I'm not criticising ORMs, just how active record works.


Well it's trivial in ActiveRecord to avoid n+1s by preloading associations. As with any technology, if you use it wrong and inefficently then things will be incorrect and slow.


There does seem to be a natural conflict between large data with hierarchical structure and the generally flat lists and dictionaries of Python, that quickly leads to poor performance. It usually only takes a few foreign keys to create an exponential number of queries.

But I have no idea if there are database interfaces that make this problem simplistic. In my experience with Django, anything but the most simplistic page will be so noticeable slow that one has to go through the queries and use things like select related. Occasionally it is also better to just grab everything into memory and do operations in Python, rather than force the data manipulation to be done as a single database query.

It is a good tool for its purpose, but it is no replacement for SQL knowledge when working with complex relational databases.



Yes you do have to work on your queries to keep them fast with growing complexity. Django also has a usable intermediate API to construct your queries, instead of writing raw SQL. Nice feature to have if you don't want to commit to a specific database yet.

And as already written above, a slow but correct page is preferable to a wrong page because you ORM is omitting related data.



ORM's always abstract away details, but you monitor for slow queries and slow endpoints and then just fix the issues when they crop up.


I'd rather have a slow page because of lazy loading, than a wrong page because the related objects are not loaded (i.e. typeorm)


lol been refactoring something like this


The ORM is OK as long as you refrain from using any inheritance. If you do, the database becomes a mess quickly and only that very Django app will be able to read and write to it (including manage.py shell). Anything else, other apps in any language or a SQL client, will be lost in a sea of tables and joins.

I've got a customer with two Django apps. One was developed enthusiastically in the object orientation way. The database is a nightmare. The other one was developed thinking table by table and creating models that mimic the tables we want to have. That's a database we can also deal with from other apps and tools.



tbh, any OOP paradigms used with db tables will end up in a clusterf*ck.


Have you worked with ActiveRecord or Ecto? Just wondering for framing your comment


Not who you’re asking, but I’ve used all 3. I think in terms of query interface you can’t go wrong with any of them. In fact, I like Ecto the most because of its separation between the concept of a “Query” (super flexible and composable) vs. a “Repo” (the module where you call an actual database operation). This helps you avoid hitting the database until you’re sure you want to.

Where Django’s ORM shines is in the modeling stage: classes in models.py are your single source of truth, relationships only need to be defined once, no separate “schema” file, and most of the time migrations can be generated automatically. It’s truly top-notch.



I think SQLAlchemy is better, personally. Still just model files, but it's data mapper pattern means you won't be hitting all the issues people do with active record.


I briefly used Ecto when trying out Phoenix framework but have not worked enough with it to form an opinion.


They switched their versioning scheme after the 1.x.

https://docs.djangoproject.com/en/dev/internals/release-proc...



Similar to bitcoin, they changed to a time-based versioning scheme. Major releases don't indicated that they DID break compatibility, but that they MIGHT HAVE, and more importantly prior versions are no longer supported. Effectively the same as a LTS release.


3 years ago I moved to fast growing startup that was founded with fast api slap-dashed together. I jammed Django down their throats and I can safely say it was the best decision we made as an Org. The teams using Django are far far more productive than the others.

When a product I think is going to need users and roles and permissions, I grab Django off the shelf and never look back.

Thank you mister reinhardt



I am trying to show the value of it in my company: fastapi + vue.js and severy short staffed.

There are so much structural mistakes in our codebase, they use async python but messed it up in all the important places yet believe that Django is slow or innadequate.

They belive that Django is too "old school" and that if you want good results you need vue.js an api and all that.

Truth is, no one has the time and experience to make something good with that.

Developpement is very slow and code is buggy management is unsatisfied with the results yet they refuse to try it out.

It seem their ideas are made up and won't change.



Yeah this is definitely Django's strength - it has a lot of the stuff you're probably going to need already implemented. Massive time saver when you're setting things up.

Python definitely holds it back though. Does it have type hints yet?



Why do you say python holds it back?


I loooove Django, any project that I work on that isn't Django causes me to yearn for it greatly. However, there's two things that have been minorly bothering me about it:

- The complete lack of any motivation to support type hints (yes I know about stubs and the other 3rd party).

- The GraphQL situation is a mess. Graphene on again off again development and Strawberry being not quite all the way stable yet sucks compared to how baller DRF is. It's still a massive fight to get subscriptions working well. It would be nice to see the foundation throw them a bone like they did with Channels.



IMHO... Django hold a high standard in terms for projects running beyond the infamous 5+ years of support... still have some projects that with minimal changes (mostly configs and dependencies that got redundant/integrated into django -like choices-) are working with the latest version, surely 5.0 will not be that drastic if you are already doing software "the django way".

Things that are Django achilles heel are not developing software "the django way", mostly anything that needs some client-side to work is a PITA, requires lots of rewriting and custom templates that at some point you gotta start looking django as a backend more like the full stack framework that was meant to be. Also anything related onto getting things to production is another PITA that hasn't been solved or touched in years, dx deployment is one of those things almost any JS Framework out there is doing things better than what django supports.



Isn't Developer DX mostly a way to get developers locked into your platform? I have avoided Next.js for this reason, it seems like just a way to funnel developers towards Vercel. DX is largely a service specific problem since its coupled to the service you are deploying to.


Django is free, in all definitions and purposes of the word. No agenda, no VC funding, no BS.


Congrats on the release to the Django community!

If anyone is curious, I updated my Django / Docker starter app to use Django 5.0 at: https://github.com/nickjj/docker-django-example

It pulls together gunicorn, Celery, Redis, Postgres, esbuild and Tailwind with Docker Compose. It's set up to run in both development and production.



where do you tend to run stuff in production? and if you were a startup - any preferences?


nice... thanks!


I can’t tell if it’s Django or just how I use it—-I’m a mechanical engineer by training and only dabble on web dev—-but I deeply appreciate how it gives me enough abstraction to get going but doesn’t get too far ahead of itself. If I go away for a year or two then come back I still get what’s going on. Meanwhile anything I try on JS land has gone through a few half-lives.


If you want a similar experience in JS check out Joystick [1]. It's being built to mimic the indefinitely stable design of stuff like Django and Rails.

[1] https://github.com/cheatcode/joystick



Which is just yet another js framework which might disappear next month.

That's the problem.



I've been using Django as my main choice for web projects for over ten years. The reason I like it so much is because it comes with a lot of built-in features that one needs to ship web projects to production. For example, I was first attracted to Django because of its admin interface and its straightforward views and templating system.

Over the years, Django has kept up with changes in web development. An example of this is when database migrations, which used to be a separate project, were integrated into Django itself. The Django community is also strong with great ecosystem projects like DRF for APIs, Django Channels for real-time features, and social-auth for social sign-ins.

My recent use of Django is in (https://github.com/trypromptly/LLMStack). We use Django Channels for WebSocket support, DRF for APIs, and ReactJS for the frontend.



What's the preferred Python Web Framework these days?

I've read a lot of love for Litestar (formerly Starlite), since it seems people prefer it over FastAPI, Flask, etc.

https://litestar.dev

Or is the preferred web framework still Django?



I've always felt, and this hasn't changed recently, that if you're going to need more than, say, 3 of the cross cutting concerns that Django provides for, then it'll be much more maintainable in the long run to just use Django rather than effectively building a custom solution out of parts. The flip side: if you're building a small internal API that only needs a couple of these, Django might be overkill.

What do I mean by "cross cutting concerns"? I'm thinking about ORM/models, migrations, admin UI, caching, sessions, misc security middleware, user accounts, validation/forms, templating, RSS feeds, logging, testing infrastructure, etc. Django's pieces all fit together well, and any time I've done this with Flask/etc I've found myself spending so much time solving issues gluing these bits together and working around impedance mismatches between libraries.

We had a large Django site at my last place and would just suggest new starters worked through the Django tutorial, because our site basically still worked like that.



I half-agree with you, I've found that there are two options when choosing a framework:

1. You're making something with 100 lines, which you're absolutely sure will stay 100 lines. Go with Flask.

2. Otherwise, Django.

Django is great at getting out of your way when you don't need its functionality, so you can just ignore most of it if you don't need it.



Second this, if you need a database and users, Django is better than the headache of thinking about this yourself with all security pitfalls. I've built several production APIs around Django (like, not CMS at all) and I find it a good compromise between an SDK and rolling your own, this is partly due to Python as well of course.

And I've done smaller things with Flask where it would make no sense to go with Django as well but those were things not really built around a db or CRUD API etc.



I agree. I would even go so far as to say that if you need an ORM, go with Django. I've wasted too much time adding SQLAlchemy to Flask to get something that is still worse than the Django ORM.


They way I'd look at it - if your app owns the database and schema, use Django. If your app is connecting into someone else's database or databases (like in enterprises with DBA priesthoods etc), the flexibility of SQLAlchemy can fit better around arbitrary schemas etc.


Perhaps, but it depends what you're building. SQLAlchemy is much more capable, so if you need great database control and don't need all the other bits Django is bringing, then I kinda get it.


+1 to that. Maybe SQLAlchemy is a better product, but being a bolted on solution makes everything about the ORM experience feel worse than using Django. If nothing else, it is not just using Flask+SQLAlchemy, now it is Flask+SQLAlchemy+Alembic. Or maybe, you want the niceties, so it is Flask+SQLAlchemy+Alembic+FlaskMigrate.


Exactly. It's the migration support that I find the best feature of Django, but I keep forgetting about it until I have to migrate with some other ORM.


Depends what you're solving for. Building a website that requires user authentication and basic relational DB... I default to Django. But if I'm building small internal services then I go FastAPI or Flask. Django's ORM is still dreamy.

I used to like DRF (Django Rest Framework) and Django + DRF was a powerful combo to drive single-page-application sites. But DRF can get a little painful if you're not using some of the out-of-the-box classes. Painful as in... lots of code to right and very hard for someone to maintain without knowledge of how DRF magic is made under the hood.



I choose between Django and Litestar these days.

I wish I had a hard and fast rule for the choice, but it's something like:

- Litestar if I know with certainty (a) the thing I'm building is and always will be a tiny service and (b) I probably won't have to evolve the backing data schema much. Wrap an ML model? Litestar. Have a small database I want to expose via API, read-mostly? Litestar.

- Django if I know (a) I'm going to be building on this over a longer timeframe, (b) I have complex user/group auth needs, (c) my data schema will likely go through substantial evolution, or (d) I will need an admin UI in the early goings, either for the managing team or for customer support.

I have plenty of SQLAlchemy+Alembic+Litestar backends but I vastly prefer the creature comforts of Django's ORM + migrations; it hits that 80% sweet spot so very well. SQLalchemy is both raw power and, often, far too much friction.

I used to choose between Django and Flask, but Litestar -- while still young -- seems to capture most of the key things I liked about core Flask but in a more modern package. (Maybe Quart, aka async Flask, will ultimately win the day; not sure.)

It's not targeted at the use case, but I wonder if Datasette will replace my need for the Django admin UI at least in some limited set of cases.

These days, most of my front-ends are React+Typescript+Vite.

(FWIW I personally avoid FastAPI entirely. I appreciate the impact it had getting the python community to think about (a) async (b) proper use of type hints in the web context and (c) the need for OpenAPI support, etc. but there are a lot of footguns and so many issues still opened that its (amazing, lovely) single maintainer probably won't get to. SQLModel -- aka the merging of Pydantic + SQLAlchemy ORM models -- is an even bigger trap, IMO.)



I know it's not "shiny and new" but Django is still serving us very well were I work.

The only two things it lacks great support of is typing and async. However the async is actively being worked on and does work (with some quirks), and python's type support has only gotten half-mature just recently (coming from typescript at least).

I would personally be hesitant to try something new just because django is so battle-tested at this stage, unless you just absolutely require better async support.



> However the async is actively being worked on and does work (with some quirks)

I recently tried to implement it in a project using the new ORM a-methods (which AFAIK are not even async under the hood) and it resulted in an explosion of complexity bubbling up in many places in the codebase. I reverted everything to sync and re-implemented the hot functions with multi-threading... I think I'll keep to this approach until I see some good guides, codebase examples, and overall feature maturity.



Have been a big Django user over the past 10 years at my startups, but we decided to do all new projects in Litestar going forwards - typing, async, and a better REST API story made it the preferred choice for us.


Still Django unless you're only building a simple API.


Why not a complex API?


If you are doing something that is basic CRUD (which, to be honest, is most of the business world, although it's not very sexy), then Django is the best. If you want to do something that doesn't fit very well into that idea, then Flask is good for "just give me a web wrapper and get out of my way".


Jetbrains Python Survey from 2022[1] has Flask, Django, Fastapi dominating the web-frameworks. Not sure how reliable this is, but I also barely see any other frameworks mentioned. So they either are in a totally different bubble, or just not popular (yet).

[1] https://lp.jetbrains.com/python-developers-survey-2022/#Fram...



I guess it depends entirely on what it is that you are building - there's no one-size-fits-all but for Python for me that is still Django.


Django; none of the new-hotness one compares. This is my no-bullshit answer that comparative articles and these frameworks' home pages dodge.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



Search:
联系我们 contact @ memedata.com