Python CGI URL Redirect



我目前正在编写一个CGI python脚本。一旦我有时间,我会在web2py中重写它,但根本没有时间ATM。

除了一件事,我已经构建了整个逻辑。我需要能够:

1) 发送一个变量以启动流程(使其工作)
2) 刷新页面,直到该过程结束
3) 处理完成后显示信息。

我似乎无法通过URL刷新部分,也无法剥离启动原始进程的变量。

我尝试了网络浏览器(webbrowser.open('http://example.com?running=1')),但由于某种原因,我在Mac上根本没有被重定向。

if print_html.parse_url():
    url_variable=print_html.parse_url()
    IP=url_variable['IP'].value
    Iterations=int(url_variable['quantity'].value)
    start=url_variable['start'].value
    refresh=url_variable['refresh'].value
if start == "1":

正如您所看到的,我从URL中读取变量,并分配值。当start=='1'时,我想开始运行其余的程序。当程序运行时,我想更改URL变量以重新读取页面,直到所有内容都完成处理

更多的澄清,也许这有助于:我需要刷新页面,或者打开同一个页面,但使用不同的变量。

例如第一个实例:http://example.com/test.py?start=1逻辑运行,然后刷新生成:第2个实例:http://example.com/test.py?running=1

这有道理吗?

您可以使用HTML meta http-equiv指令刷新页面。

#!/usr/bin/python
import datetime
import time
print "Content-Type: text/html"
print ""
print '''
<html>
<head>
<meta http-equiv="refresh" content="15" />
</head>'''
now = datetime.datetime.now()
now = now.isoformat()
print '''
<body>
The time is now %s
</body>''' % now

最新更新