Скрипт cgi не может получить поля HTML-формы

У меня настроен сервер WAMP для python cgi. Но я не мог получить значения из 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 [email protected] 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

person abhimanyuaryan    schedule 15.04.2015    source источник
comment
Мне кажется синтаксическая ошибка   -  person Bryan Way    schedule 16.04.2015
comment
@BryanWay, в чем ошибка? я скопировал все из документа python   -  person abhimanyuaryan    schedule 16.04.2015


Ответы (1)


Это синтаксическая ошибка. Из этой строки:

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

Строка, которая печатается, завершается раньше. Измените его на:

print("<p>" + form["name"].value + "</p>")
person Bryan Way    schedule 16.04.2015
comment
о, я не обратил внимания на этот закрывающий тег абзаца. большое спасибо. Теперь я не буду доверять копированию и вставке кода документов Google в интерпретатор. - person abhimanyuaryan; 16.04.2015