【问题标题】:Access HTTP PUT data in python hug在 python hug 中访问 HTTP PUT 数据
【发布时间】:2016-09-03 13:33:11
【问题描述】:
import hug

something = {'foo': 'bar'}

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

如何访问 put 数据以便更新something?我查了thisthis,但找不到任何东西。

【问题讨论】:

  • 我从未使用过这个库,但根据他们的文档,bar 似乎应该是你的函数的参数。

标签: python api python-3.x hug


【解决方案1】:
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())

【讨论】:

    猜你喜欢
    • 2016-08-19
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2011-09-15
    • 1970-01-01
    相关资源
    最近更新 更多