django-unicorn
django-htmx
Our great sponsors
django-unicorn | django-htmx | |
---|---|---|
51 | 18 | |
2,124 | 1,344 | |
- | - | |
9.0 | 8.5 | |
4 days ago | 2 days ago | |
Python | JavaScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
django-unicorn
- Use any web browser as GUI, with Zig in the back end and HTML5 in the front end
-
Coming to grips with JS: a Rubyist's deep dive
Then there are stack-specific libraries: StimulusReflex for Rails, Phoenix LiveView, Laravel Livewire, Unicorn and Tetra for Django, Blazor for .NET, … and the list goes on.
- Unicorn – A full-stack web framework for Django
-
Reflex – Web apps in pure Python
- you get one of the best ORMs in existence with great relationship handling and generated admins
https://www.django-unicorn.com/
Not 1.0 yet but I'm using it in production and omgosh is it easy to crank out UIs.
-
Django 4.2 Released
There'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/
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)
-
Launch HN: Pynecone (YC W23) – Web Apps in Pure Python
I think all LiveView frameworks should be part of this.
Here are two Python ones I've tried:
-
Frontend framework for django?
Django Unicorn is the closest thing that answers the question IMO. Personally, I've never used it since I don't want to lock myself into a Django-only way of doing things (at least, more often than I have to).
Have you looked into Django Unicorn?
-
Rails has Hotwire (which as I understand is an SPA-like integrated frontend with much reduced complexity), is there something analogous in Django? Is this what HTMX is? I really don't want to learn React or Vue..
When I was exploring the space, django-unicorn looked interesting also. But HTMX got me so far, so easily, that I didn't give unicorn a fair shake.
django-htmx
- Django + Htmx package for simple integration
-
HTMX and Wagtail
To make things easier, install the django-htmx package. Then, in your Page model's serve(), you can do things like if request.htmx: and return an HTML snippet instead of the full page in that case.
-
Htmx
The great thing about HTMX is it fits really nicely with templated server-rendered frameworks like Django.
You can have a page with a list of items. The page is one template, and it includes a sub-template which is just the
- items. Then you have a separate view for "get list fragment" which just returns the updated/sorted/filtered
- . If you toggle the ordering, or filter the list, HTMX will automatically call the fragment renderer and replace just the
- items, without reloading the page.
See this example: https://github.com/adamchainz/django-htmx/blob/8054f049f53f0...
This approach solves the common interactivity use-cases requiring JS in a server-rendered app, without having to write any JS, and without having to build a REST API. Instead you just render HTML, which your framework is excellent at.
-
Building a fullstack app with Flask and HTMx
If you use django-htmx, it's pretty simple to get the "this HTTP request came from HTMX" flag and branch accordingly in your view. The docs give a simple example of the logic here:
https://django-htmx.readthedocs.io/en/latest/middleware.html...
The examples give a fleshed-out version: https://github.com/adamchainz/django-htmx/blob/main/example/...
Though that's very slightly different than how I described it above, but it's basically the same idea; in this case you commonize the `main` block between the two contexts.
-
What are your favorite 3rd party packages that you often use with Django?
Have a look, it’s pretty cool: https://github.com/adamchainz/django-htmx
Nice. I've written some less complete, less consistent variant of this a couple times now. That alone may be worth taking the dependency.
-
Recommendations for combining the power of Django with the dynamic feeling of Javascript (SPAs)
The Modern JavaScript guides are fantastic resources if you want a detailed guide to integrating JavaScript into Django: https://www.saaspegasus.com/guides/modern-javascript-for-django-developers/. I have a few other articles listed on https://www.django-unicorn.com/articles for other approaches. It does seem like Django developers have converged around HTMX for simpler interactivity. I've used https://github.com/adamchainz/django-htmx in the past which helps integrate Django and HTMX.
-
My first real project with Django - hncustomnewsletters
Also checkout django-htmx if you haven’t. Htmx makes it buttery to sprinkle ajax on a form without writing any JavaScript
-
Guides or examples of useful Django + HTMX patterns?
Adam Johnson's django-htmx utility library for using HTMX in views (views.py)
-
Update only part of webpage upon click
If you don't want to learn a whole frontend framework, I'd take a look at htmx. Here is a nice tutorial to get you started: https://www.mattlayman.com/blog/2021/how-to-htmx-django/, and here is a package that integrates Django with htmx a little bit: https://github.com/adamchainz/django-htmx.
What are some alternatives?
reflex - Web apps in pure Python. 🐍
htmx - </> htmx - high power tools for HTML
PyWebIO - Write interactive web app in script way.
flet - Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
Flask - The Python micro framework for building web applications.
fastapi - FastAPI framework, high performance, easy to learn, fast to code, ready for production
Quasar Framework - Quasar Framework - Build high-performance VueJS user interfaces in record time
inertia-laravel - The Laravel adapter for Inertia.js.
nicegui - Create web-based user interfaces with Python. The nice way.
livewire - A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
streamlit - Streamlit — A faster way to build and share data apps.
jetstream - Tailwind scaffolding for the Laravel framework.