class documentation

class Response:

View In Hierarchy

Represents the non-IO parts of an HTTP response, specifically the status and headers but not the body.

This class is not meant for general use. It should only be used when implementing WSGI, ASGI, or another HTTP application spec. Werkzeug provides a WSGI implementation at :cls:`werkzeug.wrappers.Response`.

New in version 2.0.
Parameters
statusThe status code for the response. Either an int, in which case the default status message is added, or a string in the form {code} {message}, like 404 Not Found. Defaults to 200.
headersA ~werkzeug.datastructures.Headers object, or a list of (key, value) tuples that will be converted to a Headers object.
mimetypeThe mime type (content type without charset or other parameters) of the response. If the value starts with text/ (or matches some other special cases), the charset will be added to create the content_type.
content​_typeThe full content type of the response. Overrides building the value from mimetype.
Method __init__ Undocumented
Method __repr__ Undocumented
Method access​_control​_allow​_credentials.setter Undocumented
Method content​_range.setter Undocumented
Method content​_security​_policy.setter Undocumented
Method content​_security​_policy​_report​_only.setter Undocumented
Method delete​_cookie Delete a cookie. Fails silently if key doesn't exist.
Method get​_etag Return a tuple in the form (etag, is_weak). If there is no ETag the return value is (None, None).
Method mimetype.setter Undocumented
Method retry​_after.setter Undocumented
Method set​_cookie Sets a cookie.
Method set​_etag Set the etag, and override the old one if there was one.
Method status.setter Undocumented
Method status​_code.setter Undocumented
Class Variable accept​_ranges Undocumented
Class Variable access​_control​_allow​_headers Undocumented
Class Variable access​_control​_allow​_methods Undocumented
Class Variable access​_control​_allow​_origin Undocumented
Class Variable access​_control​_expose​_headers Undocumented
Class Variable access​_control​_max​_age Undocumented
Class Variable age Undocumented
Class Variable allow Undocumented
Class Variable charset Undocumented
Class Variable content​_encoding Undocumented
Class Variable content​_language Undocumented
Class Variable content​_length Undocumented
Class Variable content​_location Undocumented
Class Variable content​_md5 Undocumented
Class Variable content​_type Undocumented
Class Variable cross​_origin​_embedder​_policy Undocumented
Class Variable cross​_origin​_opener​_policy Undocumented
Class Variable date Undocumented
Class Variable default​_mimetype Undocumented
Class Variable default​_status Undocumented
Class Variable expires Undocumented
Class Variable last​_modified Undocumented
Class Variable location Undocumented
Class Variable max​_cookie​_size Undocumented
Class Variable vary Undocumented
Instance Variable headers Undocumented
Property access​_control​_allow​_credentials Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request.
Property cache​_control The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
Property content​_range The Content-Range header as a ~werkzeug.datastructures.ContentRange object. Available even if the header is not set.
Property content​_security​_policy The Content-Security-Policy header as a ~werkzeug.datastructures.ContentSecurityPolicy object. Available even if the header is not set.
Property content​_security​_policy​_report​_only The Content-Security-policy-report-only header as a ~werkzeug.datastructures.ContentSecurityPolicy object. Available even if the header is not set.
Property is​_json Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`.
Property mimetype The mimetype (content type without charset etc.)
Property mimetype​_params The mimetype parameters as dict. For example if the content type is text/html; charset=utf-8 the params would be {'charset': 'utf-8'}.
Property retry​_after The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client.
Property status The HTTP status code as a string.
Property status​_code The HTTP status code as a number.
Property www​_authenticate The WWW-Authenticate header in a parsed form.
Method ​_clean​_status Undocumented
Instance Variable ​_status Undocumented
Instance Variable ​_status​_code Undocumented
def __init__(self, status=None, headers=None, mimetype=None, content_type=None):

Undocumented

Parameters
status:t.Optional[t.Union[int, str, HTTPStatus]]Undocumented
headers:t.Optional[t.Union[t.Mapping[str, t.Union[str, int, t.Iterable[t.Union[str, int]]]], t.Iterable[t.Tuple[str, t.Union[str, int]]]]]Undocumented
mimetype:t.Optional[str]Undocumented
content​_type:t.Optional[str]Undocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
@access_control_allow_credentials.setter
def access_control_allow_credentials(self, value):

Undocumented

Parameters
value:t.Optional[bool]Undocumented
@content_range.setter
def content_range(self, value):

Undocumented

Parameters
value:t.Optional[t.Union[ContentRange, str]]Undocumented
@content_security_policy.setter
def content_security_policy(self, value):

Undocumented

Parameters
value:t.Optional[t.Union[ContentSecurityPolicy, str]]Undocumented
@content_security_policy_report_only.setter
def content_security_policy_report_only(self, value):

Undocumented

Parameters
value:t.Optional[t.Union[ContentSecurityPolicy, str]]Undocumented
def delete_cookie(self, key, path='/', domain=None, secure=False, httponly=False, samesite=None):
Delete a cookie. Fails silently if key doesn't exist.
Parameters
key:strthe key (name) of the cookie to be deleted.
path:strif the cookie that should be deleted was limited to a path, the path has to be defined here.
domain:t.Optional[str]if the cookie that should be deleted was limited to a domain, that domain has to be defined here.
secure:boolIf True, the cookie will only be available via HTTPS.
httponly:boolDisallow JavaScript access to the cookie.
samesite:t.Optional[str]Limit the scope of the cookie to only be attached to requests that are "same-site".
def get_etag(self):
Return a tuple in the form (etag, is_weak). If there is no ETag the return value is (None, None).
Returns
t.Union[t.Tuple[str, bool], t.Tuple[None, None]]Undocumented
@mimetype.setter
def mimetype(self, value):

Undocumented

Parameters
value:strUndocumented
@retry_after.setter
def retry_after(self, value):

Undocumented

Parameters
value:t.Optional[t.Union[datetime, int, str]]Undocumented
def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None):

Sets a cookie.

A warning is raised if the size of the cookie header exceeds max_cookie_size, but the header will still be set.

Parameters
key:strthe key (name) of the cookie to be set.
value:strthe value of the cookie.
max​_age:t.Optional[t.Union[timedelta, int]]should be a number of seconds, or None (default) if the cookie should last only as long as the client's browser session.
expires:t.Optional[t.Union[str, datetime, int, float]]should be a datetime object or UNIX timestamp.
path:t.Optional[str]limits the cookie to a given path, per default it will span the whole domain.
domain:t.Optional[str]if you want to set a cross-domain cookie. For example, domain=".example.com" will set a cookie that is readable by the domain www.example.com, foo.example.com etc. Otherwise, a cookie will only be readable by the domain that set it.
secure:boolIf True, the cookie will only be available via HTTPS.
httponly:boolDisallow JavaScript access to the cookie.
samesite:t.Optional[str]Limit the scope of the cookie to only be attached to requests that are "same-site".
def set_etag(self, etag, weak=False):
Set the etag, and override the old one if there was one.
Parameters
etag:strUndocumented
weak:boolUndocumented
@status.setter
def status(self, value):

Undocumented

Parameters
value:t.Union[str, int, HTTPStatus]Undocumented
@status_code.setter
def status_code(self, code):

Undocumented

Parameters
code:intUndocumented
accept_ranges =

Undocumented

access_control_allow_headers =

Undocumented

access_control_allow_methods =

Undocumented

access_control_allow_origin =

Undocumented

access_control_expose_headers =

Undocumented

access_control_max_age =

Undocumented

age =

Undocumented

allow =

Undocumented

charset: str =

Undocumented

content_encoding =

Undocumented

content_language =

Undocumented

content_length =

Undocumented

content_location =

Undocumented

content_md5 =

Undocumented

content_type =

Undocumented

cross_origin_embedder_policy =

Undocumented

cross_origin_opener_policy =

Undocumented

date =

Undocumented

default_mimetype: str =

Undocumented

default_status: int =

Undocumented

expires =

Undocumented

last_modified =

Undocumented

location =

Undocumented

max_cookie_size: int =

Undocumented

vary =

Undocumented

headers =

Undocumented

@property
access_control_allow_credentials: bool =
Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request.
@property
cache_control: ResponseCacheControl =
The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
@property
content_range: ContentRange =

The Content-Range header as a ~werkzeug.datastructures.ContentRange object. Available even if the header is not set.

New in version 0.7.
@property
content_security_policy: ContentSecurityPolicy =

The Content-Security-Policy header as a ~werkzeug.datastructures.ContentSecurityPolicy object. Available even if the header is not set.

The Content-Security-Policy header adds an additional layer of security to help detect and mitigate certain types of attacks.

@property
content_security_policy_report_only: ContentSecurityPolicy =

The Content-Security-policy-report-only header as a ~werkzeug.datastructures.ContentSecurityPolicy object. Available even if the header is not set.

The Content-Security-Policy-Report-Only header adds a csp policy that is not enforced but is reported thereby helping detect certain types of attacks.

@property
is_json: bool =
Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`.
@property
mimetype: t.Optional[str] =
The mimetype (content type without charset etc.)
@property
mimetype_params: t.Dict[str, str] =

The mimetype parameters as dict. For example if the content type is text/html; charset=utf-8 the params would be {'charset': 'utf-8'}.

New in version 0.5.
@property
retry_after: t.Optional[datetime] =

The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client.

Time in seconds until expiration or date.

Changed in version 2.0: The datetime object is timezone-aware.
@property
status: str =
The HTTP status code as a string.
@property
status_code: int =
The HTTP status code as a number.
@property
www_authenticate: WWWAuthenticate =
The WWW-Authenticate header in a parsed form.
def _clean_status(self, value):

Undocumented

Parameters
value:t.Union[str, int, HTTPStatus]Undocumented
Returns
t.Tuple[str, int]Undocumented
_status =

Undocumented

_status_code =

Undocumented