[Python]如何将Python写的脚本嵌入到Html中应用?
我想在一个网页中实现动态显示公告的功能,我得想法是这样的,让Python脚本程序去读一个已经存在.txt文件,然后将结果以Table的形式显示在浏览器中。
在Html文件中我是这样写的:
……
<form name="scrollnews" method="POST" action="/cgi-bin/news.py"></form>
……
在news.py中实现从.txt文件中读取信息是这样的:
#!E:\Python\python.exe
def main():
newsfile = open('news.txt','r')
newsStr = newsfile.readline()
if newsStr:
print "Content-type: text/html"
print
print "<table width='800' align='center' border='0' cellspacing='0' cellpadding='0'>"
while newsStr:
print "<tr><td width='15' height='15'><div align='left'><img src='pic/dot.gif' width='14' height='14' /></div></td>"
print """
<td width='780' height='15'><div align='left'>%s</div></td></tr>""" %newsStr
newsStr = newsfile.readline()
print "</table>"
newsfile.close()
else:
newsfile.close()
main()
但是当我把Apache启动访问时,Python脚本程序却没有执行,但如果直接访问:http://localhost/cgi-bin/news.py是可以读出文件中的信息的,但就是不能实现嵌入到Html中来,而且服务器端也支持CGI了,不知道该怎么办了,请高手指教!