在 Python 烧瓶中,我使用 flask.views.MethodView 创建了一个视图,如果我不发送表单,该视图就可以工作。但是,如果我使用 xml.send(form) 发送表单,它就会挂起。
JavaScript 调用:
function jackpot() {
var form = new FormData();
var fname = "hello there";
form.append("filename", fname);
var xml = new XMLHttpRequest();
xml.open("POST", "/site/myapp/bob", true);
console.log("sent")
xml.onreadystatechange = function () {
console.log(xml.readyState);
console.log(xml.status);
if (xml.readyState == "4" && xml.status == "200"){
console.log("yes");
console.log(xml.responseText);
}
}
xml.send(form);
}
Python脚本:
import flask, flask.views
app = flask.Flask(__name__)
class View1(flask.views.MethodView):
def get(self):
pass
def post(self):
return "hello world"
#return str(flask.request.form('filename'))
app.add_url_rule('/site/myapp/bob', view_func=View1.as_view('bob'))
更新
我相信问题现在在 nginx 和 uwsgi 之间。
uwsgi 的输出:
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 16582)
spawned uWSGI worker 1 (pid: 16587, cores: 2)
spawned uWSGI worker 2 (pid: 16589, cores: 2)
spawned uWSGI worker 3 (pid: 16591, cores: 2)
spawned uWSGI worker 4 (pid: 16593, cores: 2)
[pid: 16591|app: 0|req: 1/1] 10.5.46.20 () {48 vars in 884 bytes} [Sat Sep 21 18:02:25 2013] POST /site/myapp/bob => generated 11 bytes in 5 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)
nginx配置:
server {
listen 22.22.22.22;
access_log /var/log/nginx/localhost.access_log main;
error_log /var/log/nginx/localhost.error_log info;
location / {
root /var/www/dude;
}
location /site/ {
try_files $uri @uwsgi;
}
location @uwsgi {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
}
uwsgi 配置:
one@chat-dash:~$ cat /etc/uwsgi.d/myapp.ini
[uwsgi]
socket = 127.0.0.1:3031
uid = web
gid = web
plugins = python
chdir = /site
module = myapp
callable = app
pythonpath = /python
processes = 4
threads = 2
#enable-threads = true
#daemonize = /var/log/uwsgi/myapp.log
one@chat-dash:~$