flask.Request

flask.Request

doc:http://flask.pocoo.org/docs/1.0/api/#incoming-request-data

1.      flask.Request

flask中Request类的一些属性和方法。

class flask.Request(environ, populate_request=True, shallow=False)

The request object used by default in Flask. Remembers the matched endpoint and view arguments.

It is what ends up as request. If you want to replace the request object used you can subclass this and set request_class to your subclass.

The request object is a Request subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones.

1.1.    属性

environ:The underlying WSGI environment.

path

full_path

script_root

url

base_url

url_root

提供了一些资源定位说明,也就是 IRI.

Imagine your application is listening on the following application root:

http://www.example.com/myapplication

And a user requests the following URI:

http://www.example.com/myapplication/%CF%80/page.html?x=y

In this case the values of the above mentioned attributes would be the following:

path

u'/π/page.html'

full_path

u'/π/page.html?x=y'

script_root

u'/myapplication'

base_url

u'http://www.example.com/myapplication/π/page.html'

url

u'http://www.example.com/myapplication/π/page.html?x=y'

url_root

u'http://www.example.com/myapplication/'

3、args和values:args返回请求中的参数,values返回请求中的参数和form

return json.dumps(request.args)        #url:http://192.168.1.183:5000/login?a=1&b=2、返回值:{"a": "1", "b": "2"}
return str(request.values)        #CombinedMultiDict([ImmutableMultiDict([('a', '1'), ('b', '2')]), ImmutableMultiDict([('username', '123'), ('password', '1234')])])

authorization

The Authorization object in parsed form.

content_length:正文大小,单位字节

The Content-Length entity-header field indicates the size of the entity-body in bytes or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

cookies:略

data:请求数据

file:上传的文件

headers:默认的值由WSGI提供。

The headers from the WSGI environ as immutable EnvironHeaders.

返回列表

method:请求方法,例如get/post

url:资源地址

form:返回form的内容。

return json.dumps(request.form) #{"username": "123", "password": "1234"}

猜你喜欢

转载自www.cnblogs.com/wodeboke-y/p/11113966.html