我正在尝试向我的 HTML 测试站点添加评论表单,但我无法获得将评论写入文件的表单。
<form action="/Users/kyle/server/comments.html" method="POST">
Your name: <br>
<input type="text" name="realname"><br>
<br>Your email: <br>
<input type="text" name="email"><br>
<br>Your comments: <br>
<textarea name="comments" rows="15" cols="50"></textarea><br><br>
<input type="submit" value="Submit">
</form>
我怎样才能获得表格以向文件写入评论?
这是我用于服务器的 python 代码
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
PORT_NUMBER = 8080
#This class will handles any incoming request from
#the browser
a = open("/Users/kyle/server/web-test.html")
site=a.read()
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Send the html message
self.wfile.write(site)
return
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()