我是烧瓶的新手(将它与 nginx 一起使用),我正在尝试理解 URL 逻辑。我有 2 个 python 脚本.... /site/myapp.py 和 /site/bar.py。
请教三个问题:
- 如果,我只想运行 myapp.py 而不是 /site/bar.py 如何添加 url 规则以使用 add_url_rule 运行它?
- 如果我想改为运行 /site/bar.py,我该怎么做?
- 如果我想运行 myapp.py,并有两个不同的视图...取决于
xml.open("POST", "/site/myapp/view1", true)
和xml.open("POST", "/site/myapp/view2"
,true)....如何使用 add_url_rule 为 myapp.py 中的每个视图分配一个 url?
蟒蛇脚本/site/myapp.py:
root@chat:/site# cat myapp.py
import flask, flask.views
app = flask.Flask(__name__)
class View1(flask.views.MethodView):
def post(self):
pass
app.add_url_rule('/site/myapp', view_func=View1.as_view('view1'))
root@chat:/site#
Javascript函数:
function foo() {
var xml = new XMLHttpRequest();
xml.open("POST", "/site/myapp", true);
xml.send(form);
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);
}
}
}
nginx配置:
server {
listen 10.33.113.55;
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;
}
}