Python
#!/usr/bin/env python3 import cgi import html form = cgi.FieldStorage() text1 = form.getfirst("TEXT_1", "не задано") text2 = form.getfirst("TEXT_2", "не задано") text1 = html.escape(text1) text2 = html.escape(text2) print("Content-type: text/html\n") print("""<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Обработка данных форм</title> </head> <body>""") print("<h1>Обработка данных форм!</h1>") print("<p>TEXT_1: {}</p>".format(text1)) print("<p>TEXT_2: {}</p>".format(text2)) print("""</body> </html>""")
<html> <head> <meta charset="utf-8"> <title>Обработка данных форм</title> </head> <body> <form action="/cgi-bin/form.py"> <input type="text" name="TEXT_1"> <input type="text" name="TEXT_2"> <input type="submit"> </form> </body> </html>
from http.server import HTTPServer, CGIHTTPRequestHandler server_address = ("",8000) httpd = HTTPServer(server_address, CGIHTTPRequestHandler) httpd.serve_forever()