0
我是新烧瓶(使用它与nginx),我想了解URL逻辑。我有2个python脚本.... /site/myapp.py和/site/bar.py。2个不同脚本和不同视图的Python烧瓶URL逻辑
我有三个问题,请:
- 如果,我想只运行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"
,真正的)......我将如何分配在每个 视图的URL中myapp.py与add_url_rule ?
python脚本/site/myapp.py:
[email protected]:/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'))
[email protected]:/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;
}
}
Flask没有类似CGI或PHP的路由系统。 URL方案可能看起来与文件系统结构完全不同。请从[快速入门](http://flask.pocoo.org/docs/quickstart/)或[教程](http://flask.pocoo.org/docs/tutorial/)开始, –