werkzeug Request

WSGI application接收两个参数:“environment”和“start_response”。
requestclass 可以包装environ,方便对environ进行操作

from werkzeug.wrappers import Request, Response

def application(environ, start_response):
    request = Request(environ)
    response = Response("Hello %s!" % request.args.get('name', 'World!'))
    return response(environ, start_response)

也可以写成

from werkzeug.wrappers import Request, Response

@Request.application
def application(request):
    return Response("Hello %s!" % request.args.get('name', 'World!'))

使用requestclass需要遵守以下规则:
1.requestobject是不可变的,不要试图改变他的属性
2.requestobject可以在线程中共享,但不是线程安全的,如果想在多线程中获得它,使用locks
3.不可以序列化requestobject

class werkzeug.wrappers.BaseRequest(environ, populate_request=True, shallow=False)
属性描述
environ
shallow
_get_file_stream
access_route
classmethod application(f)
args
base_url
charset = ‘utf-8’
close()
cookies
data
dict_storage_class
disable_data_descriptor = False
encoding_errors = ‘replace’
files
form
form_data_parser_class
classmethod from_values(*args, **kwargs)
full_path
get_data(cache=True, as_text=False, parse_form_data=False)
headers
host
host_url
is_multiprocess

参考:
https://werkzeug.palletsprojects.com/en/1.0.x/wrappers/?highlight=request#base-wrappers

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值