10 ms·
Django 4.2 Released
- TeeWEE 4y agoDjango is cool. But miss the type safety. FastAPI is better but is openapi spec second. Not easy for clients. However now doing mostly Kotlin with Ktor and loving it. Just a better language which makes it much easier to trust the compiler. Lot less unit testing needed. And Kotlin feels really pythonic
- locusofself 4y agoI've been away from python for quite some time but enjoyed using django on a project 5-6 years ago. I thought it was really full-featured and fairly intuitive, but it seemed to rely heavily on what seems to be considered an older paradim of submitting forms, and getting sent to a new page, etc, vs the "Single Page Application" concept. I know it was possible to do SPAs with django-rest or something, but I'm curious if Django has mostly stayed in this "older" paradigm or if its more .. modernized at this point?
- roger20 4y agohttps://www.django-rest-framework.org/ https://www.django-rest-framework.org/
- crop_rotation 4y agoDjango is ver good if you are writing non SPA with a SQL backend. If you are writing a SPA without a SQL backend (any of the noSQL DBs), it becomes much easier to just use flask/quartz/fastAPI, as you don't benefit from the Django niceties.
- Klonoar 4y agoIt’s fine even if you’re writing an SPA, the “niceties” don’t really get in the way at all.
- varispeed 4y agoand when you find yourself actually needing "niceties" they are right there waiting... I've been trying those alternative libraries from time to time and there is always the thought "I wish I started this in Django" when project becomes more complex than a basic endpoint.
- sgt 4y agoDRF works really well. You'll inevitably have some other pages that require non SPA, for example your login pages, signup and things like that. So regular Django forms come in handy there.
- nagyf 4y agoDoes SPA concept work well with search engines? I moved away from web development, but SPAs used to be very bad if you wanted to appear in Google search. Btw I was looking into Django recently, they are still using the “older” paradigm you are referring to.
- crop_rotation 4y agoI think Google is capable of handling SPAs these days (it can execute js now), so works fine mostly (might still be better to serve full HTMLs to start with).
- bmelton 4y agoIt technically can render javascript, but there's a performance penalty that negatively affects your crawl budget. If you're twitter or facebook, or have enough domain reputation already that your crawl budget is big enough to offset, then it doesn't matter. If you are not already a big deal, then it takes a lot of off-site traction to overcome. Practically speaking, for two otherwise-even sites just starting out, a statically rendered site has a pretty significant SEO advantage over a JS-only site.
- 411111111111111 4y ago(Which is why hydration is a thing)
- petr25102018 4y agoYou can server-side render the SPA. Not with Django, but with things like Nuxt or Next. Then the SEO penalty is just the increased page size (maybe some extra loading time). But at least the content can be crawled normally.
- boolean 4y agoThe old paradigm is new again. Combining Django with HTMX, you get the simplicity of rendering HTML on the server side and not deal with bloated and over-engineered Javascript frameworks. Flask/Django with HTMX and Tailwindcss is a fantastic combination and my current preferred stack. I also add Alpinejs to this mix for interactivity. Really enjoying the heightened productivity that this setup provides.
- ryanisnan 4y agoThis looks really interesting. I haven't come across HTMX before, but I'll give it a look.
- jerrygenser 4y agoI tried out htmx + django a little but got stuck doing something more than trivial. Do you have an example of a starter project that has intermediate concepts demonstrated? Maybe this can help me get over the hump.
- kumshw 3y agoAnother solid alternative to htmx is unpoly (https://unpoly.com/ https://unpoly.com/) and there's an exhaustive writeup on how to use unpoly with django as well here https://www.spapas.net/2023/04/04/using-unpoly-with-django/ https://www.spapas.net/2023/04/04/using-unpoly-with-django/
- soperj 4y agoHonestly, the SPA concept is flawed, and throws away all the good things that HTML gave you out of the box. I'm glad people are starting to come to their senses and are moving away from it.
- chungy 4y agoLike everything, they are useful as a tool in certain contexts, particularly the application context. Just don't try to pretend it's a "good for everything" tool.
- Mimmy 4y agoDo you mind elaborating on the good things HTML gives you out-of-the-box that SPAs throw away?
- guhcampos 4y agoMeaningful back/forward buttons, for one! (I know this is not HTML per se, but it's by far my biggest pet peeve with SPA since forever, so I had to mention it.)
- jononomo 4y agoYou only have to build the application once, for one thing. With SPAs you have to build the application on the backend and then build it again on the front end.
- veidelis 4y agoNot necessarily.
- viraptor 4y agoSPA is just "a way" to do things. You're describing them as older/modern, but they're simply different approaches to achieve different things.
- PrivateButts 4y agoFor fancier, SPA style applications we utilize Strawberry to add GraphQL support into Django. It's pretty enjoyable to work with, but I would love for GraphQL to get more love from Django officially. Subscriptions are still a bit thorny, but have come a long way now that ASGI and channels are a focus for the Django team.
- samwillis 4y agoThere's a brilliant project called Django Unicorn that aims to be the equivalent of Laravel Livewire for Django. You should take a look. https://www.django-unicorn.com/ https://www.django-unicorn.com/ That and HTMX + Alpine.js are a strong combination. (I also had a bash at building a similar tool for Django called Tetra but unfortunately haven't had the time needed to commit to it: https://www.tetraframework.com https://www.tetraframework.com)
- cultofmetatron 4y agobut how does it stack up against phoenix liveview? ;)
- nesarkvechnep 4y agoIt’s probably slower.
- sgt 4y agoCan you use HTMX + jQuery for the glue logic?
- simonw 4y agoI'm relieved to see that the idea that SPAs are a "modern", better way of doing things seems to finally be fading a little bit. My experience from lessons learned over the past ten years is that SPAs generally take longer to build, are usually slower to load, have much worse accessibility and are more expensive to debug and maintain. For a great deal of web projects you're better off with the "old paradigm". That said... I do think there's an argument to be made that Django should include core framework features that make working with SPAs easier, rather than farming that out entirely to Django REST Framework. Django 4.2 does have one nod in that direction: https://docs.djangoproject.com/en/4.2/releases/4.2/#django-contrib-staticfiles https://docs.djangoproject.com/en/4.2/releases/4.2/#django-c... - "ManifestStaticFilesStorage now has experimental support for replacing paths to JavaScript modules in import and export statements with their hashed counterparts".
- pen2l 4y agoWhy not just absorb DRF? Which as I understand is the leading choice for many, so I wonder if some effort should be dedicated to reducing fragmentation.
- deleted 4y ago[deleted]
- simonw 4y agoThe problem with having things like DRF inside of Django core is that it reduces their speed of iteration. Django releases a new version every six months. Packages that aren't part of Django core are free to release on a different schedule, which really helps when you're trying to innovate on something new. In DRF's case it's now mature and stable enough that maybe that wouldn't be so much of a problem... but it's still not clear to me that having it in Django core would be a net benefit (aside from as a marketing thing) than having it live independently as it does today.
- miiiiiike 4y agoThe problem with DRF being an external package is that it does thing slightly different than Django itself would do it. DRF’s validators don’t implement `__eq__`, Serializers doesn’t implement `serializer._meta.fields` on the base class (you have to instantiate the serializer to access anything other than `declared_fields`), lack of async view support, and on and on. I find DRF grating and would pay anything to have an official Django REST api contrib package.
- elAhmo 4y agoDjangi can also work well with turbolinks
- guggle 4y agoA few things: 1/ "older" paradigm is still extremely useful in many cases 2/ we also use Django as a backend for SPAs. Here with Vuetify 3/ using the HTMX paradigm, you're both doing SPA and "older paradim of submitting forms"
- Gordonjcp 4y agoWhy would you want to do SPA? What does it actually do to improve life for users?
- tmnvix 4y agoYou might want to look into HTMX (https://htmx.org/ https://htmx.org/). It's very popular in the Django community.
- dham 4y agoYou might not keep up with things on Twitter, but SPAs are out. It's really a relic of an older time.
- cutler 4y agoSurely a better metric would be actual jobs as advertised on Indeed.com where there's a metric ton of React jobs which doesn't look like changing anytime soon regardless of what may be happening on Twitter.
- dham 4y agoYea, React is moving to the server. Check out Remix, which pushes the more "old school" approach of doing forms. I think Next is coming soon with something for that.
- forgotpwd16 4y agoWhat replaces them?
- bbbbzzz1 4y agoI 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?
- crop_rotation 4y agoIf you use a RDBMS then Django is a very good choice whether you use SPA or not.
- bshipp 4y agoI 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
- znpy 4y agoIt’s boring, well documented, has a ton of modules, extensible, solid, robust, reliable, trustworthy. I’d pick it for these reasons.
- surfingdino 4y agoDjango'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.
- hooverd 4y agoI personally prefer Django Ninja over DRF for APIs, it's all the good parts of FastAPI mixed with Django.
- zach_garwood 4y agoHonestly, 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.
- canadiantim 4y agoI love Django, but I can’t help but feel FastAPI > Django these days.
- simonw 4y agoDoes Django's increasing levels of support for asyncio balance things back for you at all?
- tmpz22 4y agoNot GP but $work is DRF + React. For new projects async runtimes are enticing but its really hard to switch to or from a async runtime with an existing project. Similarly moving to or from the Django ORM or SQLAlchemy + Pydantic is too much work for most to justify. So whatever fully featured framework you start with will be the one you stick with. They all have warts and hurdles but should get you where you need to be from a business perspective.
- thewataccount 4y agoWe use django for our websites where I work, and I use it for personal projects for the ORM. How do you like the ORM for FastAPI? I've wanted to try it but since I already know how to use django it's been hard to find a reason to try FastAPI. Currently I _really_ like Django's orm.
- Zetice 4y agoYou end up missing Django's ORM when you can't use it, as well. I've tried my best to recreate the experience with Prisma in JS but it took me awhile to get to a place where I felt like I wasn't duplicating schema...
- barefeg 4y agoFastAPI doesn’t come with an ORM out of the box. There’s https://sqlmodel.tiangolo.com/ https://sqlmodel.tiangolo.com/ which wraps SQLAlchemy and allows defining the database models with pydantic-like classes. For me neither Django nor SQLAlcjemy hit the right spot when trying to define “pure” domain models that have no dependency (I.e. no ORM information). For that I created a repository pattern approach that converts “domain mode operations” into SQLModel query operations via filter specifications (https://martinfowler.com/apsupp/spec.pdf https://martinfowler.com/apsupp/spec.pdf). The result is that I always need to define 2 models: one is my pure domain model and another is a “table model” (defined in SQLAlchemy) along with a mapping between the two (for cases where there’s no 1-to-1 trivial mapping between their fields). Also making some of the SQLAlchemy magic (for example back propagating relational attributes) is messy. But if you want to produce some quick applications I think SQLModel+FastAPI works quite well. I don’t think is as mature as Django though.
- varispeed 4y agoDjango Rest Framework for getting services up and running quickly is a godsend. If service needs extra performance then can be rewritten in Golang later.
- karlosos 4y agoIn what scenarios it would be beneficial to rewrite the Django app in Go? Do you mean something specific when saying that Go would be good replacement?. I/O heavy or computation heavy service?
- chocolatkey 4y agoI actually did to rewrite parts of django's auth, caching in go in order to be compatible with a grpc-based mobile app. The django source code is well documented and easy enough to understand, so it wasn't a probablem signing sessions, creating users etc in go and then using them in django. For django itself, once I slapped a database caching layer on top and tuned gunicorn/uvicorn, there were no performance issues. Go is faster, but django is fast enough.
- winrid 4y agoYou don't need to do a full rewrite usually. Just pull one or two CPU intensive routes out into their own service.
- epivosism 4y agoI keep wanting to switch personal projects to use my professional language C#, but there still is nothing as reasonable as a django default admin view with CRUD for the entities you create, so I always go back.
- paulddraper 4y agoI'm seriously considering adding Django admin to my Node.js project. Like, keep the Node.js code but use Django admin. Are there any comparable projects to Djano admin? A database model that generates an optionally customizable admin UI?
- epivosism 4y agoI've looked a lot in C# world but haven't found anything. It's surprising.
- luxcem 4y agoIn the node.js universe maybe something like https://strapi.io/ https://strapi.io/
- paulddraper 4y agoThanks I'll look.
- techdragon 4y agoHave you looked at ServiceStack? It’s not free and not exactly equivalent to Django but it is one of the closest I’ve found for C#