文件I / O后不会打印Python CGI

时间:2017-07-09 00:06:22

标签: python html cgi

#!/usr/bin/env python
import cgi
print "Content-type: text/html"
print

print """
<html>

<head><title>your details are as follows</title></head>

<body>

  <h3> Sample CGI Script </h3>
"""

form = cgi.FieldStorage()
username = form.getvalue('Username')
ipaddress = form.getvalue('IPaddress')
subnetmask = form.getvalue('Subnetmask')

print username
print ipaddress
print subnetmask

上面的python代码工作正常并打印出html以及上面的用户名,ipaddress和subnetmask打印语句。 但是,当我添加以下代码时,FIle I / O之后的任何打印语句都不会打印到网页上。无论如何,文件I / O上方的所有打印都将打印到网页

searchfile = open("IP.txt", "r")
for line in searchfile:
    if ipaddress in line: print "IP set to null already"
searchfile.close() 

任何人都可以向我解释如何让它发挥作用。我真的希望将打印声明if ipaddress in line: print "IP set to null already"打印到网页上

0 个答案:

没有答案