Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run python code using html5 [closed]

Basically I want to create a sexy GUI using HTML5 then call code that I wrote in python. I have just discovered some tutorials about web2py, however I am getting the videos now from youtube so I can only watch when I get home. (Life of a student with no internet at home).

So basically I have written a python script, now I want to use a webpage to interact with that script instead of terminal as I have been doing. So I have a webpage provide me the GUI to my python app.

Hope this makes more sense.

Any help and direction will be greatly appreciated.

Thanks in advance

like image 939
Kwekuq Avatar asked Feb 20 '14 16:02

Kwekuq


People also ask

Can Python run on HTML5?

A very common application for HTML5 in the modern world of Python programming is display inside of IPython notebooks. This is usually done with either HTML5 or Javascript.

Can you execute Python from HTML?

The new PyScript project lets you embed Python programs directly in HTML pages and execute them within the browser without any server-based requirements.

How do I keep a Python script open after running?

cmd /k is the typical way to open any console application (not only Python) with a console window that will remain after the application closes. The easiest way I can think to do that, is to press Win+R, type cmd /k and then drag&drop the script you want to the Run dialog. Fantastic answer. You should have got this.

Can Python code be embedded in HTML?

It is possible to run embed Python within a HTML document that can be executed at run time.


1 Answers

You need to flip that around, you want to run server-side python code that renders your sexy HTML5 GUI. There are many Python frameworks that are suitable to this, including web2py, django, and my personal favorite flask.

Any of these frameworks will let your python code run, then render the HTML with python variables/functions available by using a templating engine (for example Flask uses Jinja template). Tutorials are readily available for all of these python libraries, but if you want to take a look at Flask, I can recommend Miguel Grinberg's excellent tutorial series.

like image 76
binaryatrocity Avatar answered Sep 18 '22 13:09

binaryatrocity