大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
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
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185264.html原文链接:https://javaforall.net
