8 ms·
Unicorn – A full-stack web framework for Django
- xwowsersx 3y agoGiven gunicorn and uvicorn, I can't help but feel this name can and will cause some confusion. We gotta be able to pick different names lol
- cdchn 3y agoI was definitely instantly confused when I saw this.
- xwowsersx 3y agoThanks for confirming. I knew it couldn't be just me!
- mkl95 3y agoGuinicorn coming next!
- melx 3y agoThere's Hypercorn too.
- vram22 3y agoWe really need an Uncorn(y) name ...
- dandellion 3y agoThey should have called it Djunicorn.
- xwowsersx 3y agoHahaha
- ano88888 3y agoisn't Django already a web framework?
- jer0me 3y agoSee also: Laravel Livewire (https://livewire.laravel.com https://livewire.laravel.com) HTMX (https://htmx.org https://htmx.org) Hotwire (https://hotwired.dev/ https://hotwired.dev/) Phoenix LiveView (https://github.com/phoenixframework/phoenix_live_view https://github.com/phoenixframework/phoenix_live_view)
- guggle 3y agoAnd https://unpoly.com/ https://unpoly.com/
- bdcravens 3y agoStimulus Reflex (Ruby), which predates Hotwire, also deserves a mention, though most of its momentum seemed to stall when Hotwire was announced. https://docs.stimulusreflex.com/ https://docs.stimulusreflex.com/
- Alifatisk 3y agoYes, StimulusReflex deserves some highlight because they were one of the first to introduce this approach!
- a_bored_husky 3y agoSlightly longer list here: https://github.com/liveviews/liveviews https://github.com/liveviews/liveviews
- throwaway154 3y agoDoes class TodoView(UnicornView): create a model? class UnicornView(TemplateView) and from django.views.generic.base import TemplateView Is this Django magic a Flasker doesn't get?
- selcuka 3y agoAs far as I understand UnicornView attributes (such as `self.tasks`) simply synchronise client state with the server side. It doesn't seem to automagically create a model instance unless you specifically do it.
- kbaker 3y agoThis is correct. It looks like there is good integration with existing Django models: https://www.django-unicorn.com/docs/django-models/ https://www.django-unicorn.com/docs/django-models/
- pabe 3y agoI wondered how Unicorn compared to htmx. They're giving an answer on their website: htmx and alpine.js are great libraries to provide interactivity to your HTML. Both of those libraries are generalized front-end framework that you could use with any server-side framework (or just regular HTML). They are both well-supported, battle-tested, and answers to how they work are probably Google-able (or on Stackoverflow). Unicorn isn’t in the same league as either htmx or alpine.js. But, the benefit of Unicorn is that it is tightly integrated with Django and it should “feel” like an extension of the core Django experience. For example: * redirecting from an action uses the Django redirect shortcut * validation uses Django forms * Django Models are tightly integrated * Django messages “just work” the way you would expect them to * you won’t have to create extra URLs/views for AJAX calls to send back HTML because Unicorn handles all of that for you
- devmunchies 3y agoI wouldn’t consider htmx “battle tested”.
- foul 3y agoIsn't htmx intercooler.js without jquery, which is (intercooler) a 10 years old library been used extensively in a lot of sites?
- outofpaper 3y agoEssentially yes. See https://news.ycombinator.com/item?id=23331672 https://news.ycombinator.com/item?id=23331672
- devmunchies 3y agofunny, the reason i say its not battle tested is because of an issue i discovered in the extension system that was mentioned in that post.
- Takennickname 3y ago
- tedunangst 3y agoIsn't unicorn the ruby web server? Name collisions are kinda unavoidable, but I'd at least try to avoid them in the same space.
- guggle 3y agoAlso Gunicorn…
- ocimbote 3y agoHow painful if you had to have 2 friends with the same first name... Name collision is unavoidable and one of the many wrong battles to fight for, IMO.
- Biganon 3y agoGunicorn is literally one of the 2 most used wsgi servers for Django. This name is objectively confusing.
- ofrzeta 3y agoHow is it a "full-stack framework" when it's "for Django" that provides the backend service? Also on their own homepage they mention "Using other frontend frameworks with Django", so I'll conclude it is in fact a frontend framework for Django.
- deleted 3y ago[deleted]
- pmontra 3y agoThis is subjective and in part marketing but given that it is installed with pip install django-unicorn and used with from django_unicorn.components import UnicornView like any other python module used in a Django app, I'd say that it brings the full stack inside Django, much like its counterparts for Laravel, Phoenix and Rails. What was only backend plus server side generated pages is also Javascript now, written inside the backend without even having to know Javascript.
- ofrzeta 3y agoAs in "alternative views for Django"?
- pmontra 3y agoThey almost surely work together with Django standard views and templates. A Django view prepares the data for the template that renders the HTML page. Then some of that HTML talks with the Unicorn views declared in the attributes of its tags.
- andrewstuart 3y agoI've done extensive development with Flask, Bottle, Django, Falcon, Django Rest Framework, Starlette, Sanic and FastAPI over about 13 years or so. These days I prefer to build my back end applications with nodejs, TypeScript and plain SQL (no ORM) talking to Postgres. I like Django but it pissed me off no end that it's called "batteries included", except that the very first thing you need to do with any Django project is going and find some batteries for the user signup auth flow. That's not batteries included, and its not something you should need to figure out for yourself in a batteries included framework. It's time consuming, complex and error prone and should be built in. Anyhow as I say, I've prefer nodejs though I still do use Python for lots of stuff.
- tomwojcik 3y agoThat doesn't make sense. Django-allauth is the standard for non-rest Auth flow, django-rest-auth and djoser for rest API Auth flow. Each implementation is tailored for a slightly different case. There's a reason why only admin views are kind of built in and if you want you can expose admin to the end user and it supports the entire Auth flow out of the box.
- andrewstuart 3y agoBatteries included means the stuff you need for most uses is already included. The fact that there are many possible add ins to solve this doesn't address the fact that Django does not include core functionality for web applications.
- kurjam 3y agoYou mentioned running nodejs + typescript over extensive frameworks like django now. Curious if you chose to write your own framework or are you using something from nodejs space to do "batteries included" thing for you? Asking because I've had some experience with nest.js and even though it's fun it often feels hackish and a bit messy even when solving standard issues like authorization that's not a simple app wide RBAC.
- nologic01 3y agoGreat to see the growing effort to explore all the fields left uncultivated by the breathless SPA/angular/react/vue bandwagons of the past decade. It feels like a ratonal reallocation of tasks to where they can be executed best. Something that is nagging me though is the (still) rather incomplete take on client-side reactivity. Alpine.js is by-and-large addressing this in a pleasantly minimalistic way, but for this new take to become a defacto standard of lean and mean modern web development I feel there should be uniform semantics and integration that spans the different server-side stacks. This way code and knowledge would be reusable and not tied to a specific language/web platform.
- vorticalbox 3y agoReminds me a lot of https://fresh.deno.dev/ https://fresh.deno.dev/
- EmilStenstrom 3y agoDjango was a "batteries included" framework about 10 years ago. But the core team had very strong opinions about javascript, saying that picking a javascript framework should NOT be part of those batteries. Time has passed, and javascript is now part of every single website or app we build. Django still doesn't give any help to developers that wants to build a modern site. My opinion: They should go the Phoenix Live View-route: adding a small websocket js layer, that permits reactivity while deferring as much logic to the backend as possible.
- __pache__ 3y ago...you can just _do_ that? Channels, model save fires realtime frontend update, frontend handles that update. Would be an awesome pattern to demonstrate, but doesn't have to be built in..
- wiseowise 3y ago> Time has passed, and javascript is now part of every single website or app we build That’s the problem - it shouldn’t be.
- sjamaan 3y agoIf they had chosen a JS framework as part of the batteries, that framework probably would've been deprecated by now. For instance, who still builds websites with Angular or Backbone/Marionette anymore? See also Rails, which did choose a battery quite early on: prototype.js. Well, that was a wrong decision, so they changed it to jQuery (which is now also deprecated; no idea what it supports nowadays) and also dropped their RJS templating language. Lots of breakage and churn on every major release for us poor sods who made use of such features.
- pjerem 3y ago> Angular A LOT of companies ?
- jeremycarter 3y agoOh. I don't know. Just half of the biggest sites in the world from Google...
- samwillis 3y agoUnicorn is awesome, and I think most would agree that it's the Django communities answer to Livewire/Liveview/etc. Adam has built a brilliant project and the time he must dedicate to it is amazing! Last year I had a month free and I had a go at building something for Django in this area, with a bunch of interesting ideas - built on Alpine.js, resumable server side component state, inline component templates. But sadly time is limited and I just can't spend the time needed to push it further. One day I may be able to pivot back to it, but would be very happy for someone to take some of these ideas and run with them - https://www.tetraframework.com/ https://www.tetraframework.com/ What I really want to see is a modern asset + front end build solution for Django. It would enable more of these sorts of projects. Thats what needs to be built into Django.
- sgt 3y agoMy first thought when seeing their validation examples - when I build a Django app and add validations, I start off with a normal form that does a full submit. This is the easiest to get going. As requirements become a bit more complex, I might add JS validation so that a POST is not necessary. Looking at their validation examples: https://www.django-unicorn.com/examples/validation https://www.django-unicorn.com/examples/validation This does a POST each time, albeit automatically on typing. It still means a lag for a kind of validation that could have been done client side.
- thraxil 3y ago> This does a POST each time, albeit automatically on typing. It still means a lag for a kind of validation that could have been done client side. If you can accept that lag, the tradeoff is that you only have to write the validation logic once, in one language. Furthermore, if your validation includes something like "check that this username isn't already registered" that requires server-side logic, you're stuck with that POST request and lag anyway.
- sgt 3y agoAgreed. Rather maybe spend time on your UX and ensure that the form is understandable by the user. And by deploying closer to the edge, the latency should be pretty low.
- drcongo 3y agoShame there's no jinja support, I really can't stand Django templates.
- rajasimon 3y agoYou can use Jinja with Django https://docs.djangoproject.com/en/4.2/topics/templates/#django.template.backends.jinja2.Jinja2 https://docs.djangoproject.com/en/4.2/topics/templates/#djan...
- doix 3y agoI guess the biggest problem/downside/flaw with this is that you wait for a response from the backend to update the UI. Which is mostly fine, but I've come to expect either a round trip to the server, or instantaneous updates. This is the uncanny valley for me, it's neither the old school web or "SPA land" (for a lack of a better term). In the todo example, I write some garbage and press "Add", there is absolutely 0 feedback anything happened. I then press it again. About 100ms later, the first thing I typed appeared, then slightly later it got replaced with nothing. I have no idea how I'd fix that in this framework, there's too much magic for me to figure out where I'd insert a "fix" for this. I'd probably start writing my own javascript to disable the button while it's submitting (which isn't great, but better than today), at which point the "magic" is lost.
- entropyneur 3y agoI've only learned about Unicorn from this HN post, so take it with a grain of salt, but this appears to be addressed by the framework itself: https://www.django-unicorn.com/docs/loading-states/ https://www.django-unicorn.com/docs/loading-states/
- ubercore 3y agoUpdate state isn't quite the same, though -- take the word counting example. That's not easily solvable as far as I can tell.
- michaelyin 3y ago[dead]
- Ultimatt 3y agoDoes anyone know of something similar but targeting FastAPI and SQLModel?
- robbywashere_ 3y agoReact aside… hooks, classes redux fatigue whatever- JSX is beautiful and any other framework that builds this quasi irb+mustache+html-like-markup is taking 2 steps back. I would like to see JSX survive the framework wars of 2024-2025
- toshk 3y agoI think main issue is that react is easy to integrate with node, next etc. But python, php (laravel) etc. cant just run react-dom on the server. However would be interesting to see react-dom builders for php & python that would allow you to user react as a templating language in Laravel & Django.
- reducesuffering 3y agoI abandoned Django purely because JSX is so superior to Django templating + adhoc JS. Even if you pivot to Django Rest Framework, you will immediately feel the creaky 10 year old Java EE class based approach that doesn't make intuitive sense until you wade into the magic variables and methods.
- deleted 3y ago[deleted]
- pid-1 3y agoI wish there was something like Streamlit, but for non-data apps. Personal sites, blogs, etc... Something that skipped templating and allowed me to declare compenents in a high level way. ST was easily the most pleasant experience I've ever had developing front end using a Python backend.
- adparadox 3y agoI'm the creator of Unicorn, so this is neat to see it on Hacker News again. I've been working on Unicorn nights and weekends since July 2020, slowly adding in new functionality and improving it. I have a conference talk explaining the origins a little bit: https://github.com/adamghill/djangocon-eu-2021-conference-talk https://github.com/adamghill/djangocon-eu-2021-conference-ta.... I never expected Unicorn to completely replace larger SPA frameworks, but I have found it solves for most of the use cases I need for my sites. Thanks for checking it out -- all PRs are greatly appreciated to add new features or fix bugs!