You can use Python on the web, instead of Javascript.
Yes, really.
There's a project named Brython: "A Python 3 implementation for client-side web programming".
So how does it work:
Step 1: Include Brython
<script type="text/javascript" src="/src/brython.js"></script>
Step 2: Write your code, say
<body onload="brython(1)">
<script type="text/python">
from browser import document, alert
def echo(ev):
alert("Hello {} !".format(document["zone"].value))
document["test"].bind("click", echo)
</script>
<p>Your name is : <input id="zone" autocomplete="off">
<button id="test">clic !</button>
</body>
Step 3: Demo https://brython.info/gallery/hello.html
More resources,
Top comments (9)
But why?
What are the advantages?
I personally find it appealing since I'm learning Python. Wouldn't take it to production, tough...
it's fun
I mean, sure, I do like writing in Python more than JavaScript ... but other than that, what advantages are there?
Mostly syntactic sugar i guess. I'd love to be able to use list/dict comprehensions, named arguments, but most of all, format strings.
In theory that's very cool, but I tested it for an extension project where I needed python,
that was very painful to use for the moment, because brython doesn't support some functions related to DOM, etc.
So I hope this will get better and better.
Cool module tho. :)
Has this any benefit? I mean, it seems like this adds a new complexity layer to any project without any benefit, everything which is a wrapper or non native become slower and non maintainable in a long term.
Up to now this just push a personal preference without even consider the disadvantages of the tech debt it will generate.
Mind, blown. Thank you.
JS is a magic language for browser/DOM/frontend stuff... it's useless to use another language (made with other kind of stuff in mind).
But, hey, It looks cool anyway.