簡體   English   中英

cgi腳本無法獲取html表單字段

[英]cgi script can't get html form fields

我為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

這是語法錯誤。 從這一行:

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

正在打印的字符串將盡早終止。 更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM