odoo - 当 type="json" 时,Odoo 控制器避免使用 json-rpc
问题描述
我有以下路线:
@http.route([
'/whatever/create'
], auth="none", type='json', methods=['POST'], csrf=False)
我用它来发送一个带有 json 数据的 post 请求。
有什么方法可以避免在路由上使用 json-rpc 响应type="json"
?我只想回答普通的json。
如果不可能,有没有办法通过使用`type="http"来获取放在body请求上的json数据?
解决方案
@http.route('/whatever/create', auth='public', methods=['POST'], type='http')
def index(self, **kw):
data = request.httprequest.data
return 'success'
以上代码在 Odoo 中定义
url = "http://localhost:8069/whatever/create"
param = {
"type_operation": "PTI",
"label": "",
}
headers = {'Content-type': 'text/plain'}
r = requests.post(url, data=json.dumps(param), headers=headers)
以上代码我从 py 文件中请求
发送请求时,您应该更改 Content-type
'Content-type': 'application/json' --- > 'Content-type': 'text/plain'
同样在返回时只接受字符串
return {'status': 'success'} ---> return 'success'
推荐阅读
- python - 用scrapy刮掉网址
- c - 我的程序无法读取和显示文件中的内容
- python - Python:在语音识别中获取系统音频而不是麦克风
- python - python中使用PlaySound(),simpleaudio,pygame,winsound时没有声音
- kubernetes - 使用 Raspberry Pi 和 kubernettes
- java - Payara 服务器启动异常
- android - Flutter SoundPool 播放声音问题
- python - pandas OHLC 仅随时间绘制高值
- node.js - 执行 http 请求时无法识别使用导入的(必需)路由文件
- java - 在 arrayList 中添加对象