UWSGI挂起HTML表单帖子

时间:2013-09-21 18:04:31

标签: python nginx flask html-form uwsgi

在Python烧瓶中,我使用flask.views.MethodView创建了一个视图,如果我不发送表单,它就可以工作。但是,如果我发送一个带有xml.send(表单)的表单,它就会挂起。

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 config:

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 config:

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:~$ 

1 个答案:

答案 0 :(得分:1)

这里什么都没有。 Flash正确返回您的回复。但是你的JavaScript没有看到它,因为你在定义回调之前调用了send,这是错误的回合方式。