我正在使用 Python 作为 HTTP 云函数,并希望将默认错误处理程序设置为返回 JSON 而不是 HTML。
from flask_expects_json import expects_json
import payment_orders_schema
from flask import jsonify, Flask
schema = payment_orders_schema.schema
app = Flask(__name__)
@app.errorhandler(400)
def bad_request(error):
return jsonify({'error': error.description}), 400
@expects_json(schema)
def add_payment_order(request, methods=['POST']):
request_json = request.get_json(silent=True)
if request_json:
return jsonify(request_json), 200
Run Code Online (Sandbox Code Playgroud)
首先,我不确定是否可以app在云函数中定义变量,其次,它@app.errorhandler不起作用,云函数返回 HTML。
有任何想法吗?
如何检索 createAt 时间戳晚于特定日期的文档?
就像是:
firstDayOfMonth = datetime.date.today().replace(day=1)
transactions = db.collection('productTransactions').where('createdAt', ">=", firstDayOfMonth).get()
Run Code Online (Sandbox Code Playgroud)