我正在运行一个带有自定义httpSimpleServer的小型Python应用程序以适应'POST'方法。错误:root:MiniFieldStorage - 运行在httpSimpleServer上的Python和Flask的问题
应用程序应该大写输入到表单中的所有字母并返回它们。
我得到一个错误,在终端,我GOOGLE了无济于事,我需要改变以获得此应用程序的工作?
的index.html
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Enter some text</h1>
<h2>(it will be converted to uppercase)</h2>
<form action="." method="POST" name="text">
<input type="text">
<input type="submit" name="my-form" value="Send">
</form>
</body>
</html>
flask_app.py
from flask import Flask
from flask import request
from flask import render_template
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("templates/index.html")
@app.route('/', methods=['POST'])
def my_form_post():
text = request.form.index.html
processed_text = text.upper()
return processed_text
if __name__ == '__main__':
app.debug = True
app.run()
SimpleServer.py
import SimpleHTTPServer
import SocketServer
import logging
import cgi
import cgitb
cgitb.enable()
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
logging.error(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
logging.error(self.headers)
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
for item in form.list:logging.error(item)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
终端错误消息
ERROR:root:Host: localhost:8000
Connection: keep-alive
Content-Length: 12
Cache-Control: max-age=0
Origin: http://localhost:8000
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: http://localhost:8000/templates/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: Pycharm-2c79b07b=b4744dcc-07ae-4e39-9d94-06d7a2fcf11c
ERROR:root:MiniFieldStorage('my-form', 'Send')
127.0.0.1 - - [26/Feb/2017 22:11:21] "POST /templates/ HTTP/1.1" 200 -