将参数从 angular 的 $http 传递到 python tornado 服务器
Passing parameters from angular's $http to python tornado server
我正在尝试从我的 angular frontend to my python/tornado 后端传递变量。这是我的代码。
// JS
var columns = ["col_A", "col_B", "col_C"];
var url = "working url, I confirmed it hits the server before I tried passing parameters";
var req = {
method: "GET",
headers: {
'Content-Type': undefined
},
data: {
"columns": columns
}
}
return $http.get(url, req);
/*
I also tried
var req = {
url: url,
method: "GET",
headers: {
'Content-Type': undefined
},
data: {
"columns": columns
}
}
$http.get(req);
but got a 404 with this
*/
---------------------------------------------------------------------------------------------
## python
import tornado.web
import tornado.gen as gen
class MyRequestHandler(tornado.web.RequestHandler):
def __init__(self, *args, **kwargs):
super(MyRequestHandler, self).__init__(*args, **kwargs)
@gen.coroutine
def get(self, *args, **kwargs):
import pdb
pdb.set_trace()
# ... rest of the get function
## later on
http = tornado.web.Application([
(r"/working route", MyRequestHandler, {}),
... etc
因此,在我的代码使用 pdb.set_trace() 语句暂停进行调试后,我查看了变量。查看 self.request,我看到了一堆可能与我的请求相关的内容(协议、主机、headers 等),但我不知道如何访问参数 "columns".我试过了
print self.get_argument("columns")
然后得到了 404。我真的很难过。这个设置我做错了什么?我认为这一定是可能的,我只是错过了一些非常愚蠢的事情。
在 $http 调用中使用参数而不是日期
这将导致数据被 GET 调用参数化
如果你真的在做任何其他事情,你可以使用 'data'
var req = {
method: "GET",
headers: {
'Content-Type': undefined
},
params: {
"columns": columns
}
}
我正在尝试从我的 angular frontend to my python/tornado 后端传递变量。这是我的代码。
// JS
var columns = ["col_A", "col_B", "col_C"];
var url = "working url, I confirmed it hits the server before I tried passing parameters";
var req = {
method: "GET",
headers: {
'Content-Type': undefined
},
data: {
"columns": columns
}
}
return $http.get(url, req);
/*
I also tried
var req = {
url: url,
method: "GET",
headers: {
'Content-Type': undefined
},
data: {
"columns": columns
}
}
$http.get(req);
but got a 404 with this
*/
---------------------------------------------------------------------------------------------
## python
import tornado.web
import tornado.gen as gen
class MyRequestHandler(tornado.web.RequestHandler):
def __init__(self, *args, **kwargs):
super(MyRequestHandler, self).__init__(*args, **kwargs)
@gen.coroutine
def get(self, *args, **kwargs):
import pdb
pdb.set_trace()
# ... rest of the get function
## later on
http = tornado.web.Application([
(r"/working route", MyRequestHandler, {}),
... etc
因此,在我的代码使用 pdb.set_trace() 语句暂停进行调试后,我查看了变量。查看 self.request,我看到了一堆可能与我的请求相关的内容(协议、主机、headers 等),但我不知道如何访问参数 "columns".我试过了
print self.get_argument("columns")
然后得到了 404。我真的很难过。这个设置我做错了什么?我认为这一定是可能的,我只是错过了一些非常愚蠢的事情。
在 $http 调用中使用参数而不是日期 这将导致数据被 GET 调用参数化
如果你真的在做任何其他事情,你可以使用 'data'
var req = {
method: "GET",
headers: {
'Content-Type': undefined
},
params: {
"columns": columns
}
}