<py> - Run Python in Your HTML

I know this is not specifically for Django, but couldn’t this be a gamechanger for how Django-templates (and more) works?

I hope you are up for the debate. :slight_smile:

Found here: https://pyscript.net/

<html>
    ...
    <py-script> print('Now you can!') </py-script>
</html>

I’m not sure what you’re looking for here.

Pyscript runs in the browser. It’s intended as a way to run Python in the client, not in the server - so it doesn’t really affect Django. It’s a replacement (or supplement) to JavaScript.

Or are you saying you’d like to see something like that introduced as another template rendering engine?

If so, I hope not. If anything like that ever gets introduced into Django, I won’t be using it.

I’ve spent a total of about 10 years working in and with systems that make it easy to mix business logic with presentation (Java/Spring, PHP) - and I can tell you they’re a maintenance nightmare. Trying to identify a specific source for a data element being displayed on a page ends up being far more difficult than it needs to be.

I like the fact that I’m forced to collect my data in the view, and specifically identify what’s going to be visible to the template engine when a template is rendered. It’s a big net-plus from where I sit and I hope it never changes.

Me neither :smiley: Debate (just like your response, I guess)

I (not being a professional) just thought it sounded like we could avoid doing “Javascript tricks” in the frontend and keep doing python “all the way”.
Learning python I found it confusing mixing the different syntax and commands and thought it would improve many peoples full stack experience.

I can agree with that. I’m no fan of JavaScript - although it has gotten better through the years, and I’m always needing to keep certain reference pages available whenever I try to do something with it.
I wouldn’t even (necessarily) want the full Python standard library implemented. If there were a way to simply implement the standard JavaScript API using Python syntax, I’d be happy with that.

I wouldn’t say it doesn’t affect Django. If you haven’t seen it, take a look at Simon Willison’s blogpost about running Datasette Lite web application directly in a browser. A pure browser implementation is a very different use case from a backend used by a company. That doesn’t mean that django can’t play a part in simple, portable, client side browser applications. We just haven’t had the opportunity to try this out before.

For clarity, it doesn’t affect “Django the software package”. Using it isn’t doesn’t change how you write a view to respond to a request. If you’re already writing views to respond to AJAX requests from JavaScript, switching to PyScript could be transparent if the requests being made are the same.