【问题标题】:cgi script can't get html form fieldscgi 脚本无法获取 html 表单字段
【发布时间】:2015-04-16 21:14:13
【问题描述】:

我为 python cgi 设置了 WAMP 服务器。但是,我无法从 html 表单中获取值。我已经标记了我在 python 文件中得到错误的位置。如果我删除该行错误。

HTML:

<body>

<h1>Fill out this form</h1>

<form action="test.py" method="POST">
     Enter your name: <input type="text" name="name">
     Enter age: <input type="text" name="age">

     <input type="submit" value="submit">
</form>

</body>

test.py:

#!C:\Python34\python

import cgitb
import cgi


form = cgi.FieldStorage()

print("""
<h1>Thanks for registering</h1>
""")

print("<p> form["name"].value")  # <--- If i remove this line the error goes

错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable     to complete your request.

Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

【问题讨论】:

  • 在我看来是语法错误
  • @BryanWay 有什么错误?我从 python doc 复制粘贴了所有内容

标签: html cgi python-3.4


【解决方案1】:

这是一个语法错误。从这一行开始:

print("<p> form["name"].value")

正在打印的字符串提前终止。将其更改为:

print("<p>" + form["name"].value + "</p>")

【讨论】:

  • 哦,我没有注意那个结束段落标签。多谢。现在我不相信将 google docs 代码复制粘贴到解释器了。
猜你喜欢
  • 2023-03-04
  • 2011-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多