我有一个路由,用于响应用户的POST
请求。我返回一个dict
作为响应。问题是,在某些情况下,返回字典可以正常工作,但有时会出现错误。
请问有人能解释一下什么是理想的返回类型,以及为什么在某些情况下返回dict
会成功吗?
@app.route('/getuser', methods = ['post'] )
def getusername():
user = request.json.get("user_name")
# This works good for few cases
return {"username": user}
# Whereas other require this
return jsonify({"username": user})