在 python 拥抱中访问 HTTP PUT 数据

Access HTTP PUT data in python hug

import hug

something = {'foo': 'bar'}

@hug.put('/')
def update_something():
    something['foo'] = <value_of_bar_from_http_put_request>

如何访问放置数据以便更新 something?我查找了 this and this 但找不到任何内容。

import hug

something = {'foo': 'bar'}

@hug.put()
def update_something(bar: hug.types.text):
    something['foo'] = bar
    return something  # may be

然后你可以使用requests来测试

import requests

print(requests.put('http://localhost:8000/update_something',
    data={'bar': 'foobar'}).json())