8 ms·
I'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,
by locusofself 4y ago
I'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 3y 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?