如何创建带有按钮的网页,这些按钮可以在服务该网页的系统上调用各种Python脚本? [英] How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage?

查看:69
本文介绍了如何创建带有按钮的网页,这些按钮可以在服务该网页的系统上调用各种Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名业余爱好者(并且是相当新的)程序员,他已经用python编写了几个有用的脚本(对我而言)来处理各种系统自动化任务,这些任务涉及复制,重命名和下载文件以及其他各种活动。

I'm a hobbyist (and fairly new) programmer who has written several useful (to me) scripts in python to handle various system automation tasks that involve copying, renaming, and downloading files amongst other sundry activities.

我想创建一个由我的系统之一提供的网页,该网页仅会显示一些按钮,使我可以远程启动这些脚本。

I'd like to create a web page served from one of my systems that would merely present a few buttons which would allow me to initiate these scripts remotely.

问题是我不知道从哪里开始研究如何做。假设我有一个脚本,叫做:

The problem is that I don't know where to start investigating how to do this. Let's say I have a script called:

file_arranger.py

做什么我需要让网页执行该脚本吗?这不是供公众消费,因此任何轻巧的东西都很棒。对于奖励积分,我需要研究什么才能为网络用户提供此类脚本的输出?

What do I need to do to have a webpage execute that script? This isn't meant for public consumption, so anything lightweight would be great. For bonus points, what do I need to look into to provide the web user with the output from such scripts?

编辑:第一个答案让我意识到我忘记了包括

edit: The first answer made me realize I forgot to include that this is a Win2k3 system.

推荐答案

此页面很好地描述了运行python CGI脚本所需执行的操作,并提供了示例。首先从最简单的情况开始。只需制作一个简短的脚本即可打印html。

This page on the python site has a good description and example of what you need to do to run a python CGI script. Start out with the simplest case first. Just make a short script that prints html.

#!/usr/bin/python                   #on windows change to your path to the python exe

print "Content-Type: text/html"     # HTML is following
print                               # blank line, end of headers
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"

第一次尝试时,最困难的部分通常是弄清楚放置脚本的位置和如何使Web服务器识别并运行它。如果您使用的是apache网络服务器,请查看这些配置步骤

When you try this the first time, the hardest part is usually figuring out where to put the script and how to make the web server recognize and run it. If you are using an apache web sever, take a look at these configuration steps.

一旦有了这个简单的脚本,您只需要添加一个html表单和按钮标签,并使用action属性将其指向您想要的脚本即可运行。

Once you have this simple script working, you will just need to add an html form and button tag and use the action property to point it to scripts you want to run.

这篇关于如何创建带有按钮的网页,这些按钮可以在服务该网页的系统上调用各种Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆