使用 AWS Chalice,假设app.py
如下所示:
from chalice import Chalice, Response
from chalicelib.utils import some_class
app = Chalice(app_name='myApp')
app.debug = True
@app.route('/myRoute',
methods=['POST'],
content_types=['application/octet-stream'])
def myRoute():
some_class_instance = some_class()
some_class_instance.some_def()
return Response(
body={'hello': 'world'},
headers={'Content-Type': 'application/json'})
并在utils.py
:
import requests
from chalice import Response
class some_class:
def some_def():
return Response(
body={'key1': 'val1'},
headers={'Content-Type': 'application/json'})
如果写成如图所示,return 语句 fromsome_class.some_def
不会返回给客户端。但如果我some_def
从里面跑,app.py
它就会被退回。为什么?
如何从外部将对象返回给客户端app.py
?