Falcon 框架从不返回整个响应。我从curl
(或任何其他 HTTP 工具)得到的只是:
$ curl -q -D - -o - "localhost:8000/post_account?email=someone@example.com
HTTP/1.1 200 OK
Server: gunicorn/19.4.5
Date: Thu, 31 Mar 2016 11:36:49 GMT
Connection: close
content-length: 3
content-type: application/json; charset=utf-8
curl: (18) transfer closed with 3 bytes remaining to read
索引.py
这是定义路由的引导脚本。
import falcon
from routes import route_account
app = falcon.API()
post_account = route_account.RoutePostAccount()
# Routes
app.add_route('/post_account', post_account)
route_account.py
这是路由处理程序类。我查了一下,收到的结果_result = account.create_account(**_payload)
很好。
from falcon.util import uri
from objects.account_base import AccountBase
account = AccountBase()
class RoutePostAccount(object):
@staticmethod
def on_get(req, resp):
# Convert query parameters string to dict
_payload = uri.parse_query_string(req.query_string)
# Create account
_result = account.create_account(**_payload)
# Send response
resp.status = _result.get('status', {}).get('code')
resp.body = _result
网络服务器
$ gunicorn index:app
有人看到我没看到的吗?谢谢你的帮助。