DEV Community

Cover image for Add Some Magic to Your Django Website

Add Some Magic to Your Django Website

Adam Hill on August 17, 2020

Django has been, rightly or wrongly, derided in some circles for not keeping up with modern web development. It even came up in some of the comment...
Collapse
 
rafeqm profile image
Muhammad Rafiqi

Thank God! Finally there is a Django tool that I can use to cool my head now. You don't how how many round I've been knocked down by React (and friends) and ASGI Django. I almost leave my status as a Django fans like 2 months ago. But now you bring me back to my lovely Django! Thanks man!

Collapse
 
edelvalle profile image
Eddy Ernesto del Valle Pino

Hi Adam, I'm the author of django-reactor I love your project. Is super simple and your JavaScript is better than mine, I actually improved some things in reactor based on your project. Thanks!

Collapse
 
adamghill profile image
Adam Hill

Oh, nice! I really wanted to keep adding PRs to django-reactor, but after seeing Livewire I got the itch to create something very similar without dealing with websockets at all. I do shout out django-reactor on the first page of my documentation, though! :) django-unicorn.com/documentation

Collapse
 
edelvalle profile image
Eddy Ernesto del Valle Pino

I will add support for AJAX as a second option if the websocket drops or configurable, in case you don' want websockets at all.

Collapse
 
sathishweb profile image
Sathish Ramani

Excellent! I am someone who faced the exact same dilemma after learning and trying out Django in a side project. I am now learning Flutter and contemplating of using Flutter(mobile/web)->gRPC/gRPC-web->Go/Python as the stack for my projecs. But, then, I won't probably need python+Django in that case except for the ORM and admin page advantages it provides. As you say Flutter/Angular/React will also be a heavy lift for some simple projects which don't need the advantages of those frameworks. Thanks for this post and the django-unicorn framework. I will try it out sometime.

Collapse
 
iancleary profile image
Ian Cleary (he/him)

FastAPI with Vue for me 😊

Nice article and Django is great!

Collapse
 
gayanhewa profile image
Gayan Hewa

Having tried out Livewire for a project, I don't think I will be using anything else for any of my projects that involve PHP. The developer experience is pretty neat, especially cutting down the javascript fatigue. Great to see something similar in the Django community. +1

Collapse
 
ashirvadz profile image
Ashirvad Zaiantchick

Hi Adam.

This is a wonderful project, thank you for creating it! I think it can help on my project. It has a sidebar, and I wanted it to have a component that is a progressbar tracking the user's disk usage on the server.

So far I have created the component successfully using django-unicorn and inserted it into the sidebar. It calculates the disk space percentage and resizes the progressbar accordingly.

Forgive my ignorance, but I can't find a way to change the component's properties outside it's class file, or from my own views.py file. Is it possible to do so? My goal is to update the component whenever there's some user action that impacts his disk usage.

Thanks!

Collapse
 
adamghill profile image
Adam Hill

Hi Ashirvad, wow that's awesome to hear that django-unicorn might be useful for your project. I haven't thought too much about this use case, but it might be doable in the future. When the user does an action would it be via some Javascript? I'm wondering if there was a hook to call from Javascript to update the component if that could work.

When you mention the views.py portion, I'm wondering if the page is going to be re-rendered altogether? In which case, I think the component just needs to get the correct data in real-time via API or database call or whatever.

In any event, if you could create a Github issue at github.com/adamghill/django-unicor..., that would be helpful for me and we can talk about your issue more in-depth.

Thanks!

Collapse
 
ashirvadz profile image
Ashirvad Zaiantchick

Hi Adam.

I have just created a Github issue.
Thanks!

Ashirvad

Thread Thread
 
adamghill profile image
Adam Hill

Here is the Github issue and my response in case it’s useful for anyone else: github.com/adamghill/django-unicor....

Collapse
 
adamghill profile image
Adam Hill

Yep, FastAPI looks awesome. It's hard to give up all of the niceties that Django gives me, though!

Collapse
 
haruanm profile image
Haruan Justino

This seems really promising, I was going in the same way, removed the API and was going to try Stimulus and turbolinks.
For sure I will try this.

Collapse
 
adamghill profile image
Adam Hill

I haven't used Stimulus or Turbolinks in a "real" project, but have played around with them a little bit in toy apps. Definitely some nice ideas in both libraries!

Collapse
 
alegume profile image
Alexandre Augusto de Abreu

Very nice!!!