简体   繁体   English

当从网页上单击超链接时,如何运行python脚本?

[英]How to run a python script when a hyperlink is clicked from a webpage?

I have some code on my mac in the latest version of python idle 3, that collects certain data from a csv file that gets sent to myself and prints out the output in the terminal. 我在Mac上的最新版本的python idle 3中有一些代码,该代码从csv文件收集某些数据,然后将其发送给自己并在终端中打印输出。 I want to create a webpage that has a button or link that a user clicks and it runs the code and prints out the output of my program. 我想创建一个网页,该网页具有用户单击的按钮或链接,并且该网页运行代码并打印出程序的输出。

Eventually i want to be able to create a website with multiple links that can do the same operation. 最终,我希望能够创建一个可以执行相同操作的带有多个链接的网站。

Will i need to create an sql database? 我需要创建一个sql数据库吗? If so how?... 如果是这样怎么办?

From the sound of it, you want to use a webpage as a user interface for your python script. 从声音上看,您想将网页用作python脚本的用户界面。 Unfortunately without utilising a server-side language this is not possible. 不幸的是,如果不使用服务器端语言,这是不可能的。

Multiple options exist for reacting to a button press on the server side, with PHP being the most well known, but solutions using only python do exist, such as Flask. 有多种方法可以对服务器端的按钮按下做出反应,PHP是最著名的,但是确实存在仅使用python的解决方案,例如Flask。

If you're just after a local GUI for your script, simpler options exist within python such as Tk. 如果您只是在为脚本编写本地GUI,则python中存在更简单的选项,例如Tk。

Actually you can expose this function using a webserver and then the webpage will call the server with the right url. 实际上,您可以使用Web服务器公开此功能,然后该网页将使用正确的URL调用服务器。 Since you are using python I will recommend to take a look at Flask http://flask.pocoo.org/ great micro framework to get you started. 由于您使用的是python,因此我建议您看一下Flask http://flask.pocoo.org/优秀的微型框架,以开始使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM