使用 html5 运行 python 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21913118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:51:30  来源:igfitidea点击:

run python code using html5

pythonhtmluser-interfaceweb2py

提问by Kwekuq

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).

基本上我想使用 HTML5 创建一个性感的 GUI,然后调用我用 python 编写的代码。我刚刚发现了一些关于 web2py 的教程,但是我现在从 youtube 获取视频,所以我只能在回家时观看。(一个在家没有互联网的学生的生活)。

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.

所以基本上我已经写了一个 python 脚本,现在我想使用一个网页来与该脚本交互,而不是像我一直在做的终端。所以我有一个网页为我提供了我的 python 应用程序的 GUI。

Hope this makes more sense.

希望这更有意义。

Any help and direction will be greatly appreciated.

任何帮助和指导将不胜感激。

Thanks in advance

提前致谢

采纳答案by binaryatrocity

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.

你需要翻转它,你想要运行服务器端 python 代码来呈现你性感的 HTML5 GUI。有很多 Python 框架适合于此,包括web2pydjango和我个人最喜欢的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 Jinjatemplate). 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.

这些框架中的任何一个都可以让您的 Python 代码运行,然后使用模板引擎(例如 Flask 使用Jinja模板)呈现带有 Python 变量/函数的 HTML 。所有这些 python 库的教程都很容易获得,但如果你想看看 Flask,我可以推荐Miguel Grinberg 的优秀教程系列。