当从HTML而不是resu调用时打印的Python文件内容

2024-04-19 09:24:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两份档案,索引.html以及表格.py在Windows 10的C:\Apache24\htdocs目录中。内容如下:

你知道吗索引.html你知道吗

<html>  
<head>  
<title>demo web file python2.7</title>  
</head>  
<body>  
<form name="pyform" method="POST" action="/form.py">  
  <input type="text" name="fname" />  
  <input type="submit" name="submit" value="Submit" />  
</form>  
</body>  
</html>   

你知道吗表格.py你知道吗

#!C:\Python27/python
print "Content-Type: text/html"      

import cgi,cgitb  
cgitb.enable() #for debugging  
form = cgi.FieldStorage()  
name = form.getvalue('fname')  
print "Name of the user is:",name  

Apache服务器配置为使用以下设置运行cgi脚本:

DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride All
    Require all granted
</Directory>

以及

AddHandler cgi-script .cgi .py

当我填充文本区域并单击页面上的“Submit”按钮时,我在生成的页面上得到python文件的全部内容,而不是我放入框中的内容。你知道吗

缺了什么或者我做错了什么?非常感谢。你知道吗


Tags: textnamepyform内容inputtitlehtml