flask中的request和常用属性方法

Posted maxiaohei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flask中的request和常用属性方法相关的知识,希望对你有一定的参考价值。

request的属性和方法

request: [__class__, __delattr__, __dict__, __dir__, __doc__, __enter__, __eq__, __exit__, __format__, __ge__, __getattribute__, __gt__, __hash__, 
__init__, __init_subclass__, __le__, __lt__, __module__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__,
__subclasshook__, __weakref__, _get_file_stream, _get_stream_for_parsing, _is_old_module, _load_form_data, _parse_content_type,
accept_charsets, accept_encodings, accept_languages, accept_mimetypes, access_route, application,

args, authorization, base_url, blueprint, cache_control, charset, close, content_encoding, content_length, content_md5, content_type,
cookies, data, date, dict_storage_class, disable_data_descriptor, encoding_errors, endpoint, environ,
files, form, form_data_parser_class, from_values, full_path, get_data, get_json, headers, host, host_url, if_match, if_modified_since,
if_none_match, if_range, if_unmodified_since, input_stream,

is_json, is_multiprocess, is_multithread, is_run_once, is_secure, is_xhr, json, list_storage_class, make_form_data_parser, max_content_length,
max_form_memory_size, max_forwards,

method, mimetype, mimetype_params, module, on_json_loading_failed, parameter_storage_class, path, pragma, query_string, range, referrer,
remote_addr, remote_user,
routing_exception, scheme, script_root, shallow, stream, trusted_hosts, url, url_charset, url_root, url_rule, user_agent, values,
view_args, want_form_data_parsed]

request 接收数据的常用方式:

request.form ,前端表单提交或者post方法提交的非文件数据可以以这个方法获取,获取的结果使用 

 ‘get‘, ‘getlist‘, ‘items‘, ‘keys‘,‘to_dict‘, ‘update‘, ‘values‘,‘fromkeys‘等合适方法去除要获取的值进行处理

[__class__, __contains__, __copy__, __deepcopy__, __delattr__, __delitem__, __dict__, __dir__, __doc__, __eq__, __format__, __ge__,
__getattribute__, __getitem__, __getstate__, __gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __module__,

__ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __setstate__, __sizeof__, __str__, __subclasshook__, __weakref__,
_hash_cache, _iter_hashitems, add, clear, copy, deepcopy, fromkeys, get, getlist, items, keys, lists, listvalues, pop, popitem, popitemlist,

poplist, setdefault, setlist, setlistdefault, to_dict, update, values]

 

request.data

[__add__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, 

__gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__,

__repr__, __rmod__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, capitalize, center, count, decode, endswith, expandtabs, find,
fromhex, hex, index, isalnum, isalpha, isdigit, islower, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition,

replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill]

 

request.files,前端提交的文件,需要使用这个属性获取,暂时用的方法  

‘get‘, ‘getlist‘, ‘items‘, ‘keys‘,
 [__class__, __contains__, __copy__, __deepcopy__, __delattr__, __delitem__, __dict__, __dir__, __doc__, __eq__, __format__, __ge__, 

__getattribute__, __getitem__, __getstate__, __gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __module__,
__ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __setstate__, __sizeof__, __str__, __subclasshook__,
__weakref__, _hash_cache, _iter_hashitems, add, clear, copy, deepcopy, fromkeys, get, getlist, items, keys, lists, listvalues, pop,

popitem, popitemlist, poplist, setdefault, setlist, setlistdefault, to_dict, update, values]

 

request.args

[__class__, __contains__, __copy__, __deepcopy__, __delattr__, __delitem__, __dict__, __dir__, __doc__, __eq__, __format__, __ge__, 

__getattribute__, __getitem__, __getstate__, __gt__, __hash__, __init__, __init_subclass__, __iter__, __le__, __len__, __lt__, __module__,
__ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __setstate__, __sizeof__, __str__, __subclasshook__, __weakref__,
_hash_cache, _iter_hashitems, add, clear, copy, deepcopy, fromkeys, get, getlist, items, keys, lists, listvalues, pop, popitem, popitemlist,
poplist, setdefault, setlist, setlistdefault, to_dict, update, values]

 

根据方法,尝试使用,不符合预期查看源码

 

以上是关于flask中的request和常用属性方法的主要内容,如果未能解决你的问题,请参考以下文章

flask:request对象

Flask request 属性详解

python web开发-flask访问请求数据request

python web开发-flask中访问请求数据request

flask笔记(八):request中参数的使用(待更新)

Flask关于request一些方法和属性的整理(持续更新)