Run Python Code on Front-End

32 views
Skip to first unread message

Lightning Bit

unread,
May 22, 2023, 7:51:49 PM5/22/23
to Django users
Hello all, 

I've created an accessibility app where the speech_recognition package is utilized and triggered upon running a Python function. I can successfully run the Python code in Jupyter Lab - no problems. However, it seems impossible to activate the speech_recognition package on the front-end from my views in the Django application. 

How can one run Python code from the backend that triggers on the front-end upon clicking a button on a certain page? 

Thanks all

Muhammad Juwaini Abdul Rahman

unread,
May 22, 2023, 8:23:37 PM5/22/23
to django...@googlegroups.com
You might want to try pyscript for this.

Natively, there's no way you can run python on browser.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca5edbef-3244-4d67-ad32-3cd9741c8ccdn%40googlegroups.com.

Mike Dewhirst

unread,
May 22, 2023, 10:13:50 PM5/22/23
to django...@googlegroups.com
On 23/05/2023 10:22 am, Muhammad Juwaini Abdul Rahman wrote:
How can one run Python code from the backend that triggers on the front-end upon clicking a button on a certain page? 


Have a close look at htmx.

It doesn't run Python but will replace any targeted HTML element with output from Python (or any other code) running on the backend.

You would otherwise need a Python interpreter running in the browser. But who wants that with all the security issues entailed?

Htmx is a javascript library which enhances HTML itself. Your HTML in your template then calls your Django views directly to replace any part of a page with the result.

If htmx had been around earlier, all those famous js frameworks would never have been needed. It is a life saver.

M
-- 
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages