Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python scripts in HTML

Tags:

python

html

Is it possible to write Python scripts in HTML code similarly as you write PHP between <?php ... ?> tags?

I'd like to achieve that my Python application will run in the browser.

thank you for help

like image 377
xralf Avatar asked Apr 30 '11 14:04

xralf


People also ask

Can you embed a Python script in HTML?

PyScript is an open source web framework that allows you to create frontend web applications using Python. With PyScript, you can either embed Python code in HTML, or link to a Python file and the code will execute in the browser — without running Python in the backend.

Can you use Python functions in HTML?

Yes, but not directly; you can set the onclick handler to invoke a JavaScript function that will construct an XMLHttpRequest object and send a request to a page on your server. That page on your server can, in turn, be implemented using Python and do whatever it would need to do.


1 Answers

Python indentation requirements don't go well with mixing HTML and Python code. Therefore, the most prominent method (which is a framework called Django), uses a template engine so that the Python is never in direct contact with the HTML code.

It will be similar to PHP and not javascript, as it will run on the server-side.

There is also mod_python for Apache, but I would strongly recommend using Django, which also runs on an Apache server.

like image 51
Gustav Larsson Avatar answered Sep 23 '22 08:09

Gustav Larsson